Skip to content

fix(types): remove extends ImportMeta from ModuleRunnerImportMeta#21710

Open
YevheniiKotyrlo wants to merge 1 commit intovitejs:mainfrom
YevheniiKotyrlo:fix/remove-extends-importmeta
Open

fix(types): remove extends ImportMeta from ModuleRunnerImportMeta#21710
YevheniiKotyrlo wants to merge 1 commit intovitejs:mainfrom
YevheniiKotyrlo:fix/remove-extends-importmeta

Conversation

@YevheniiKotyrlo
Copy link

Summary

ModuleRunnerImportMeta extends ImportMeta inherits all augmented properties from the global ImportMeta interface. When consumers use skipLibCheck: false with libraries that augment ImportMeta (e.g. @types/node, Expo, React Native), TypeScript raises conflicts:

error TS2717: Subsequent property declarations must have the same type.

The extends is unnecessary — the interface already explicitly declares all needed properties (url, env, hot) and has [key: string]: any as a catch-all for any additional properties (dirname, filename, main, resolve, glob).

Changes

  • packages/vite/src/module-runner/types.ts: Remove extends ImportMeta from ModuleRunnerImportMeta
  • packages/vite/src/module-runner/createImportMeta.ts: Simplify satisfies Omit<ModuleRunnerImportMeta, 'main'> as any to satisfies ModuleRunnerImportMeta as any and remove the now-unnecessary comment — main is no longer inherited from @types/node's ImportMeta augmentation

Why this is safe

  • The [key: string]: any index signature already accepts any additional properties at runtime
  • createDefaultImportMeta and createNodeImportMeta set extra properties (filename, dirname, glob, resolve, main) via the index signature — no inheritance needed
  • build-types-check (tsconfig.check.json with types: []) passes because ImportMeta without augmentations is {}, so extends ImportMeta was already a no-op in that context
  • All 5 typecheck projects pass, full build passes, ESLint passes

ModuleRunnerImportMeta extends ImportMeta inherits all augmented
properties from the global ImportMeta interface. When consumers use
skipLibCheck: false with libraries that augment ImportMeta (e.g.
@types/node), TypeScript raises "Subsequent property declarations
must have the same type" conflicts.

The extends is unnecessary — the interface already declares all needed
properties (url, env, hot) and has [key: string]: any for the rest.
Removing it also eliminates the Omit<ModuleRunnerImportMeta, 'main'>
workaround in createImportMeta.ts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant