Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions docs/guide/api-hmr.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ if (import.meta.hot) {

## IntelliSense for TypeScript

Vite provides type definitions for `import.meta.hot` in [`vite/client.d.ts`](https://github.com/vitejs/vite/blob/main/packages/vite/client.d.ts). You can create an `vite-env.d.ts` in the `src` directory so TypeScript picks up the type definitions:
Vite provides type definitions for `import.meta.hot` in [`vite/client.d.ts`](https://github.com/vitejs/vite/blob/main/packages/vite/client.d.ts). You can add "vite/client" in the `tsconfig.json` so TypeScript picks up the type definitions:

```ts [vite-env.d.ts]
/// <reference types="vite/client" />
```json [tsconfig.json]
{
"compilerOptions": {
"types": ["vite/client"]
}
}
```

## `hot.accept(cb)`
Expand Down
2 changes: 0 additions & 2 deletions docs/guide/env-and-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ By default, Vite provides type definitions for `import.meta.env` in [`vite/clien
To achieve this, you can create an `vite-env.d.ts` in `src` directory, then augment `ImportMetaEnv` like this:

```typescript [vite-env.d.ts]
/// <reference types="vite/client" />

interface ViteTypeOptions {
// By adding this line, you can make the type of ImportMetaEnv strict
// to disallow unknown keys.
Expand Down
28 changes: 17 additions & 11 deletions docs/guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,7 @@ Vite starter templates have `"skipLibCheck": "true"` by default to avoid typeche

### Client Types

Vite's default types are for its Node.js API. To shim the environment of client-side code in a Vite application, add a `d.ts` declaration file:

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

::: details Using `compilerOptions.types`

Alternatively, you can add `vite/client` to `compilerOptions.types` inside `tsconfig.json`:
Vite's default types are for its Node.js API. To shim the environment of client-side code in a Vite application, you can add `vite/client` to `compilerOptions.types` inside `tsconfig.json`:

```json [tsconfig.json]
{
Expand All @@ -131,7 +123,15 @@ Alternatively, you can add `vite/client` to `compilerOptions.types` inside `tsco
}
```

Note that if [`compilerOptions.types`](https://www.typescriptlang.org/tsconfig#types) is specified, only these packages will be included in the global scope (instead of all visible ”@types” packages).
Note that if [`compilerOptions.types`](https://www.typescriptlang.org/tsconfig#types) is specified, only these packages will be included in the global scope (instead of all visible ”@types” packages). This is recommended since TS 5.9.

::: details Using triple-slash directive

Alternatively, you can add a `d.ts` declaration file:

```typescript [vite-env.d.ts]
/// <reference types="vite/client" />
```

:::

Expand All @@ -153,7 +153,13 @@ For example, to make the default import of `*.svg` a React component:
export default content
}
```
- The file containing the reference to `vite/client` (normally `vite-env.d.ts`):
- If you are using `compilerOptions.types`, ensure the file is included in `tsconfig.json`:
```json [tsconfig.json]
{
"include": ["src", "./vite-env-override.d.ts"]
}
```
- If you are using triple-slash directives, update the file containing the reference to `vite/client` (normally `vite-env.d.ts`):
```ts
/// <reference types="./vite-env-override.d.ts" />
/// <reference types="vite/client" />
Expand Down
1 change: 0 additions & 1 deletion packages/create-vite/template-lit-ts/src/vite-env.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/create-vite/template-lit-ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"useDefineForClassFields": false,
"module": "ESNext",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"types": ["vite/client"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
1 change: 0 additions & 1 deletion packages/create-vite/template-preact-ts/src/vite-env.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/create-vite/template-preact-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"types": ["vite/client"],
"skipLibCheck": true,
"paths": {
"react": ["./node_modules/preact/compat/"],
Expand Down
1 change: 1 addition & 0 deletions packages/create-vite/template-preact-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": [],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
1 change: 0 additions & 1 deletion packages/create-vite/template-qwik-ts/src/vite-env.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/create-vite/template-qwik-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"types": ["vite/client"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
1 change: 1 addition & 0 deletions packages/create-vite/template-qwik-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": [],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
1 change: 0 additions & 1 deletion packages/create-vite/template-qwik/src/vite-env.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/create-vite/template-react-ts/src/vite-env.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/create-vite/template-react-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"useDefineForClassFields": true,
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"types": ["vite/client"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
1 change: 1 addition & 0 deletions packages/create-vite/template-react-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": [],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
1 change: 0 additions & 1 deletion packages/create-vite/template-solid-ts/src/vite-env.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/create-vite/template-solid-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"types": ["vite/client"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
1 change: 1 addition & 0 deletions packages/create-vite/template-solid-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": [],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
2 changes: 0 additions & 2 deletions packages/create-vite/template-svelte-ts/src/vite-env.d.ts

This file was deleted.

5 changes: 3 additions & 2 deletions packages/create-vite/template-svelte-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"resolveJsonModule": true,
"types": ["svelte", "vite/client"],
"noEmit": true,
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable checkJs if you'd like to use dynamic types in JS.
Expand All @@ -13,7 +15,6 @@
*/
"allowJs": true,
"checkJs": true,
"isolatedModules": true,
"moduleDetection": "force"
},
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"]
Expand Down
1 change: 1 addition & 0 deletions packages/create-vite/template-svelte-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": [],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 0 additions & 4 deletions packages/create-vite/template-svelte/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ This template contains as little as possible to get started with Vite + Svelte,

Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.

**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**

Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information.

**Why include `.vscode/extensions.json`?**

Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
Expand Down
1 change: 1 addition & 0 deletions packages/create-vite/template-svelte/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
"sourceMap": true,
"esModuleInterop": true,
"types": ["vite/client"],
"skipLibCheck": true,
/**
* Typecheck JS in `.svelte` and `.js` files by default.
Expand Down
2 changes: 0 additions & 2 deletions packages/create-vite/template-svelte/src/vite-env.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/create-vite/template-vanilla-ts/src/vite-env.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/create-vite/template-vanilla-ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"types": ["vite/client"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
1 change: 0 additions & 1 deletion packages/create-vite/template-vue-ts/src/vite-env.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/create-vite/template-vue-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "@vue/tsconfig/tsconfig.dom.json",
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"types": ["vite/client"],

/* Linting */
"strict": true,
Expand Down
1 change: 1 addition & 0 deletions packages/create-vite/template-vue-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": [],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
Loading