Skip to content

Commit

Permalink
refactor: update client type usage
Browse files Browse the repository at this point in the history
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"]
      }
    }
    ```
  • Loading branch information
yyx990803 committed Jan 5, 2021
1 parent 9f4004d commit 245303c
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
12 changes: 8 additions & 4 deletions docs/guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ Vite uses [esbuild](https://github.com/evanw/esbuild) to transpile TypeScript in

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.

### Client Type Shims
### 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 `shim.d.ts` file in your project with the following:
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`:

```ts
import 'vite/env'
```json
{
"compilerOptions": {
"types": ["vite/client"]
}
}
```

This will provide the following type shims:
Expand Down
2 changes: 0 additions & 2 deletions packages/create-app/template-react-ts/src/shim.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/create-app/template-react-ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"types": [],
"types": ["vite/client"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
Expand All @@ -16,5 +16,5 @@
"noEmit": true,
"jsx": "react"
},
"include": ["src"]
"include": ["./src"]
}
2 changes: 0 additions & 2 deletions packages/create-app/template-vue-ts/src/shim.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/create-app/template-vue-ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"jsx": "preserve",
"sourceMap": true,
"lib": ["esnext", "dom"],
"types": ["vite/client"],
"plugins": [{ "name": "@vuedx/typescript-plugin-vue" }]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"files": [
"bin",
"dist",
"env.d.ts"
"client.d.ts"
],
"engines": {
"node": ">=12.0.0"
Expand Down

0 comments on commit 245303c

Please sign in to comment.