fix(types): remove extends ImportMeta from ModuleRunnerImportMeta#21710
Open
YevheniiKotyrlo wants to merge 1 commit intovitejs:mainfrom
Open
fix(types): remove extends ImportMeta from ModuleRunnerImportMeta#21710YevheniiKotyrlo wants to merge 1 commit intovitejs:mainfrom
YevheniiKotyrlo wants to merge 1 commit intovitejs:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ModuleRunnerImportMeta extends ImportMetainherits all augmented properties from the globalImportMetainterface. When consumers useskipLibCheck: falsewith libraries that augmentImportMeta(e.g.@types/node, Expo, React Native), TypeScript raises conflicts:The
extendsis unnecessary — the interface already explicitly declares all needed properties (url,env,hot) and has[key: string]: anyas a catch-all for any additional properties (dirname,filename,main,resolve,glob).Changes
packages/vite/src/module-runner/types.ts: Removeextends ImportMetafromModuleRunnerImportMetapackages/vite/src/module-runner/createImportMeta.ts: Simplifysatisfies Omit<ModuleRunnerImportMeta, 'main'> as anytosatisfies ModuleRunnerImportMeta as anyand remove the now-unnecessary comment —mainis no longer inherited from@types/node'sImportMetaaugmentationWhy this is safe
[key: string]: anyindex signature already accepts any additional properties at runtimecreateDefaultImportMetaandcreateNodeImportMetaset extra properties (filename,dirname,glob,resolve,main) via the index signature — no inheritance neededbuild-types-check(tsconfig.check.jsonwithtypes: []) passes becauseImportMetawithout augmentations is{}, soextends ImportMetawas already a no-op in that context