Skip to content

Commit af64c81

Browse files
committed
feat(react): 调整 TypeScript 配置和环境变量定义
- 将 env.d.ts 中的 ImportMeta 相关定义移至 vite.d.ts - 更新 tsconfig.json,添加 vite/client 和 vitest/globals 类型引用 - 删除原有的 vite.d.ts 文件
1 parent ea80dcf commit af64c81

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

templates/react/src/dts/env.d.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
/**
22
* @file env.d.ts
33
* @ref https://nodejs.org/api/process.html#processenv
4-
*/
5-
6-
/// <reference types="vite/client" />
7-
/// <reference types="vitest/globals" />
8-
4+
* @ref https://vitejs.dev/guide/env-and-mode.html#intellisense-for-typescript
5+
*/
96

107
namespace NodeJS {
118
interface ProcessEnv {
129
readonly NODE_ENV: 'development' | 'production' | 'test';
1310
}
1411
}
12+
13+
interface ImportMetaEnv {
14+
readonly VITE_API_URL: string;
15+
}
16+
17+
interface ImportMeta {
18+
readonly env: ImportMetaEnv;
19+
}

templates/react/src/dts/vite.d.ts

-16
This file was deleted.

templates/react/tsconfig.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
"forceConsistentCasingInFileNames": true,
1919

2020
"lib": ["ES2023", "DOM"],
21-
"types": ["node"],
21+
"types": [
22+
"node",
23+
// vite
24+
"vite/client",
25+
"vitest/globals",
26+
],
2227
"plugins": [],
2328
"paths": {
2429
"@/*": ["./src/*"]

0 commit comments

Comments
 (0)