Skip to content

Commit 64b082e

Browse files
committed
docs: note about unknown variables
Close #27
1 parent d53be19 commit 64b082e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,23 @@ interface ImportMetaEnv extends ImportMetaEnvAugmented {
263263
// Now import.meta.env is totally type-safe and based on your `env.ts` schema definition
264264
// You can also add custom variables that are not defined in your schema
265265
}
266+
```
267+
268+
## Forbid unknown variables
269+
270+
Since we rely on module augmentation to type `import.meta.env`, using unknown variables won’t trigger errors because the `ImportMetaEnv` interface from Vite includes a `[key: string]: string` signature.
271+
272+
To enforce stricter typing and prevent the use of unknown variables, you can set up the following:
266273

274+
```ts
275+
// lib/env.ts or wherever you want
276+
import { ImportMetaEnvAugmented } from '@julr/vite-plugin-validate-env';
277+
278+
export const env: ImportMetaEnvAugmented = import.meta.env;
267279
```
268280

281+
By using `env` instead of `import.meta.env` in your code, TypeScript will now throw an error if you try to access an unknown variable.
282+
269283
## Sponsors
270284

271285
If you like this project, [please consider supporting it by sponsoring it](https://github.com/sponsors/Julien-R44/). It will help a lot to maintain and improve it. Thanks a lot !

0 commit comments

Comments
 (0)