Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make ImportMetaEnv strictly available #19077

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions docs/guide/env-and-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ To achieve this, you can create an `vite-env.d.ts` in `src` directory, then augm
```typescript [vite-env.d.ts]
/// <reference types="vite/client" />

// By adding this line, you can make the type of ImportMetaEnv strict.
yunics-highfield marked this conversation as resolved.
Show resolved Hide resolved
declare type ViteStrictImportMetaEnv = true
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved

interface ImportMetaEnv {
readonly VITE_APP_TITLE: string
// more env variables...
Expand Down
6 changes: 5 additions & 1 deletion packages/vite/types/importMeta.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
// Thus cannot contain any top-level imports
// <https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation>

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore ViteStrictImportMetaEnv may or may not be declared by users
type ImportMetaKey = ViteStrictImportMetaEnv extends true ? never : string
yunics-highfield marked this conversation as resolved.
Show resolved Hide resolved

interface ImportMetaEnv {
[key: string]: any
[key: ImportMetaKey]: any
BASE_URL: string
MODE: string
DEV: boolean
Expand Down
Loading