Skip to content

Commit

Permalink
docs(env): mention vite/client.d.ts (vitejs#5457)
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 authored Oct 29, 2021
1 parent 1248b62 commit 012ab61
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/guide/env-and-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ If you want to customize env variables prefix, see [envPrefix](/config/index#env
- Since any variables exposed to your Vite source code will end up in your client bundle, `VITE_*` variables should _not_ contain any sensitive information.
:::

### IntelliSense
### IntelliSense for TypeScript

By default, Vite provides type definition for `import.meta.env`. While you can define more custom env variables in `.env.[mode]` files, you may want to get TypeScript IntelliSense for user-defined env variables which prefixed with `VITE_`.
By default, Vite provides type definition for `import.meta.env` in [`vite/client.d.ts`](https://github.com/vitejs/vite/blob/main/packages/vite/client.d.ts). While you can define more custom env variables in `.env.[mode]` files, you may want to get TypeScript IntelliSense for user-defined env variables which prefixed with `VITE_`.

To achieve, you can create an `env.d.ts` in `src` directory, then augment `ImportMetaEnv` like this:

```typescript
/// <reference types="vite/client" />

interface ImportMetaEnv extends Readonly<Record<string, string>> {
readonly VITE_APP_TITLE: string
// more env variables...
Expand Down

0 comments on commit 012ab61

Please sign in to comment.