[unplugin] Preserve Vite plugin return types - #1848
Conversation
|
@smorimoto is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
🟡 Changes recommended
The updated index.d.ts uses typeof on a type-only import (import type vite ...), which will fail TypeScript type-checking.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates @stylexjs/unplugin’s TypeScript declarations to preserve the Vite plugin return type (instead of any), and adds a TypeScript regression fixture to ensure the factory return types remain non-any and compatible with unplugin’s VitePlugin.
Changes:
- Type
@stylexjs/unplugin/vite’s factory as returningVitePlugininstead ofany. - Reuse the Vite factory type for
stylex.vite()/unplugin.vite()in the rootindex.d.ts. - Add a dedicated TypeScript test project + fixture to assert non-
anyreturn types andVitePluginassignability.
File summaries
| File | Description |
|---|---|
| yarn.lock | Updates lock entry to include unplugin@^2.3.11 selector. |
| packages/typescript-tests/unplugin/vite.ts | New TS fixture asserting Vite factory return types are not any and satisfy VitePlugin. |
| packages/typescript-tests/tsconfig.unplugin.json | New TS config enabling skipLibCheck for the unplugin-focused type assertions. |
| packages/typescript-tests/package.json | Runs the new unplugin TS project and adds needed dev deps. |
| packages/@stylexjs/unplugin/src/vite.d.ts | Changes Vite factory return type from any to VitePlugin. |
| packages/@stylexjs/unplugin/src/index.d.ts | Shares the Vite factory type on stylex.vite via typeof. |
Review details
- Files reviewed: 3/6 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
9f635a8 to
b691d3d
Compare
What changed / motivation ?
The Vite adapter declares its return value as
any, so adding it to a Vite configuration loses plugin type information and triggerstypescript/no-unsafe-assignmentin projects using type-aware linting.Use the
VitePlugintype exported by the existingunpluginpeer dependency, and share the Vite factory declaration withstylex.vite()and the namedunpluginexport. The runtime behaviour and optional configuration argument remain unchanged.Linked PR/Issues
N/A
Additional Context
This change only updates the two Vite-related declarations.
Validation:
yarn testpassed (build, Flow, package tests, TypeScript, Prettier and ESLint).Pre-flight checklist
Contribution Guidelines