Skip to content

Commit 245303c

Browse files
committed
refactor: update client type usage
BREAKING CHANGE: client types are now exposed under `vite/client.d.ts`. It can now be included via the following `tsconfig.json`: ```ts { "compilerOptions": { "types": ["vite/client"] } } ```
1 parent 9f4004d commit 245303c

File tree

7 files changed

+12
-11
lines changed

7 files changed

+12
-11
lines changed

docs/guide/features.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ Vite uses [esbuild](https://github.com/evanw/esbuild) to transpile TypeScript in
3232

3333
Note that because `esbuild` only performs transpilation without type information, it doesn't support certain features like const enum and implicit type-only imports. You must set `"isolatedModules": true` in your `tsconfig.json` under `compilerOptions` so that TS will warn you against the features that do not work with isolated transpilation.
3434

35-
### Client Type Shims
35+
### Client Types
3636

37-
Vite's default types are for its Node.js API. To shim the environment of client side code in a Vite application, add a `shim.d.ts` file in your project with the following:
37+
Vite's default types are for its Node.js API. To shim the environment of client side code in a Vite application, add `vite/client` to `compilerOptions.types` of your `tsconfig`:
3838

39-
```ts
40-
import 'vite/env'
39+
```json
40+
{
41+
"compilerOptions": {
42+
"types": ["vite/client"]
43+
}
44+
}
4145
```
4246

4347
This will provide the following type shims:

packages/create-app/template-react-ts/src/shim.d.ts

-2
This file was deleted.

packages/create-app/template-react-ts/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"target": "ESNext",
44
"lib": ["DOM", "DOM.Iterable", "ESNext"],
5-
"types": [],
5+
"types": ["vite/client"],
66
"allowJs": false,
77
"skipLibCheck": false,
88
"esModuleInterop": false,
@@ -16,5 +16,5 @@
1616
"noEmit": true,
1717
"jsx": "react"
1818
},
19-
"include": ["src"]
19+
"include": ["./src"]
2020
}

packages/create-app/template-vue-ts/src/shim.d.ts

-2
This file was deleted.

packages/create-app/template-vue-ts/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"jsx": "preserve",
88
"sourceMap": true,
99
"lib": ["esnext", "dom"],
10+
"types": ["vite/client"],
1011
"plugins": [{ "name": "@vuedx/typescript-plugin-vue" }]
1112
},
1213
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
File renamed without changes.

packages/vite/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"files": [
1313
"bin",
1414
"dist",
15-
"env.d.ts"
15+
"client.d.ts"
1616
],
1717
"engines": {
1818
"node": ">=12.0.0"

0 commit comments

Comments
 (0)