Skip to content

[unplugin] Preserve Vite plugin return types - #1848

Open
smorimoto wants to merge 1 commit into
facebook:mainfrom
smorimoto:fix/vite-plugin-return-type
Open

[unplugin] Preserve Vite plugin return types#1848
smorimoto wants to merge 1 commit into
facebook:mainfrom
smorimoto:fix/vite-plugin-return-type

Conversation

@smorimoto

@smorimoto smorimoto commented Sep 5, 2026

Copy link
Copy Markdown

What changed / motivation ?

The Vite adapter declares its return value as any, so adding it to a Vite configuration loses plugin type information and triggers typescript/no-unsafe-assignment in projects using type-aware linting.

Use the VitePlugin type exported by the existing unplugin peer dependency, and share the Vite factory declaration with stylex.vite() and the named unplugin export. 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 test passed (build, Flow, package tests, TypeScript, Prettier and ESLint).
  • Existing TypeScript tests and targeted Prettier checks passed for the final diff.

Pre-flight checklist

Copilot AI lite review requested due to automatic review settings September 5, 2026 06:22
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 5, 2026
@vercel

vercel Bot commented Sep 5, 2026

Copy link
Copy Markdown

@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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 returning VitePlugin instead of any.
  • Reuse the Vite factory type for stylex.vite() / unplugin.vite() in the root index.d.ts.
  • Add a dedicated TypeScript test project + fixture to assert non-any return types and VitePlugin assignability.
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.

@smorimoto
smorimoto force-pushed the fix/vite-plugin-return-type branch from 9f635a8 to b691d3d Compare September 5, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants