跳至内容
TypeScript配置

TypeScript配置

tsconfig.json
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{
  "include": ["src", "*.config.ts"],
  "exclude": ["dist", "node_modules"],
  "compilerOptions": {
    // Type Checking
    "strict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "exactOptionalPropertyTypes": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noPropertyAccessFromIndexSignature": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,

    // Modules
    "types": ["vite/client"],
    "module": "esnext",
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "noUncheckedSideEffectImports": true,

    // Emit
    "noEmit": true,

    // JavaScript Support
    "allowJs": false,

    // Interop Constraints
    "erasableSyntaxOnly": true,
    "isolatedModules": true,
    "verbatimModuleSyntax": true,

    // Language and Environment
    "lib": ["ESNext", "DOM", "DOM.Iterable", "DOM.AsyncIterable"],
    "target": "esnext",

    // Completeness
    "skipLibCheck": true,
  },
}

另外,TS官方不推荐paths,更推荐Node Subpath Imports。

Note

「……Note that this feature does not change how import paths are emitted by tsc, so paths should only be used to inform TypeScript that another tool has this mapping and will use it at runtime or when bundling.……」

package.json
1
2
3
4
5
6
{
  "type": "module",
  "imports": {
    "#*": "./src/*"
  }
}
最后更新于