From 245303ca35ff2a40eca49e102b4f82cb1210f597 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 5 Jan 2021 14:01:06 -0500 Subject: [PATCH] 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"] } } ``` --- docs/guide/features.md | 12 ++++++++---- packages/create-app/template-react-ts/src/shim.d.ts | 2 -- packages/create-app/template-react-ts/tsconfig.json | 4 ++-- packages/create-app/template-vue-ts/src/shim.d.ts | 2 -- packages/create-app/template-vue-ts/tsconfig.json | 1 + packages/vite/{env.d.ts => client.d.ts} | 0 packages/vite/package.json | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) delete mode 100644 packages/create-app/template-react-ts/src/shim.d.ts delete mode 100644 packages/create-app/template-vue-ts/src/shim.d.ts rename packages/vite/{env.d.ts => client.d.ts} (100%) diff --git a/docs/guide/features.md b/docs/guide/features.md index e18ec14b3c1a96..ba72eae2f75d23 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -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: diff --git a/packages/create-app/template-react-ts/src/shim.d.ts b/packages/create-app/template-react-ts/src/shim.d.ts deleted file mode 100644 index 5c959404d1e8a6..00000000000000 --- a/packages/create-app/template-react-ts/src/shim.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// enable types for import.meta.* and file types -import 'vite/env' diff --git a/packages/create-app/template-react-ts/tsconfig.json b/packages/create-app/template-react-ts/tsconfig.json index 181704707c6996..51efd413cde175 100644 --- a/packages/create-app/template-react-ts/tsconfig.json +++ b/packages/create-app/template-react-ts/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "ESNext", "lib": ["DOM", "DOM.Iterable", "ESNext"], - "types": [], + "types": ["vite/client"], "allowJs": false, "skipLibCheck": false, "esModuleInterop": false, @@ -16,5 +16,5 @@ "noEmit": true, "jsx": "react" }, - "include": ["src"] + "include": ["./src"] } diff --git a/packages/create-app/template-vue-ts/src/shim.d.ts b/packages/create-app/template-vue-ts/src/shim.d.ts deleted file mode 100644 index 5c959404d1e8a6..00000000000000 --- a/packages/create-app/template-vue-ts/src/shim.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// enable types for import.meta.* and file types -import 'vite/env' diff --git a/packages/create-app/template-vue-ts/tsconfig.json b/packages/create-app/template-vue-ts/tsconfig.json index 5072c8fa06465d..8c7115f961a575 100644 --- a/packages/create-app/template-vue-ts/tsconfig.json +++ b/packages/create-app/template-vue-ts/tsconfig.json @@ -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"] diff --git a/packages/vite/env.d.ts b/packages/vite/client.d.ts similarity index 100% rename from packages/vite/env.d.ts rename to packages/vite/client.d.ts diff --git a/packages/vite/package.json b/packages/vite/package.json index 4b7ed6fad9e9cd..62e77f10aa6633 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -12,7 +12,7 @@ "files": [ "bin", "dist", - "env.d.ts" + "client.d.ts" ], "engines": { "node": ">=12.0.0"