ImportMetaEnv
's [key: string]
should be unknown
for type safety
#19376
Labels
ImportMetaEnv
's [key: string]
should be unknown
for type safety
#19376
Description
Using a custom env variable will by default be typed as
any
. To have the correct type, one has to use module augmentation. This is intended and working fine.But even when you augment a value correctly, you are not protected against forgetting to add more, or mistyping the value.
Unfortunately, module augmentation doesn't seem to work since the index signature was already set ! So I can't simply opt-in to:
Hence, I am requesting for
ImportMetaEnv
to default to unknown, which is more accurate, more type-safe, and would promote adding used variables inImportMetaEnv
module augmentation.Suggested solution
ImportMetaEnv
should have[key: string]: unknown
instead of[key: string]: any
Alternative
Using https://www.npmjs.com/package/patch-package to patch vite's source code on install.
Discover or request some way for module augmentation to override existing declarations.
Not include any index signature in
ImportMetaEnv
, and document that the dev should add one themselves based on the strictness they want.Additional context
Relevant ongoing typescript conversations:
any
s tounknown
microsoft/TypeScript#60899Validations
The text was updated successfully, but these errors were encountered: