@hootool/typescript-config
v0.1.3
Published
共享 TypeScript 配置基准
Readme
@hootool/typescript-config
共享 TypeScript 配置基准,提供 5 种场景的 tsconfig。
安装
pnpm add -D @hootool/typescript-config typescript可用配置
| 配置文件 | 适用场景 |
|---------|---------|
| tsconfig.base.json | 通用严格模式基准(其他配置继承自此) |
| tsconfig.react-web.json | React/H5/Web 项目 |
| tsconfig.react-native.json | React Native 项目(无 DOM lib) |
| tsconfig.vue.json | Vue 3 项目 |
| tsconfig.node.json | Node.js/CLI 工具(NodeNext 模块) |
使用
// tsconfig.json(React/H5 项目)
{
"extends": "@hootool/typescript-config/tsconfig.react-web.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src"]
}路径别名(
paths)和include需在消费者项目中自行定义,共享配置不包含相对路径设置。
基准配置要点(tsconfig.base.json)
target: ES2022strict: true(完整严格模式)moduleResolution: bundlerverbatimModuleSyntax: true(类型导入使用import { type Foo }或纯类型文件的import type,与 ESLint 内联 type specifier 对齐)moduleDetection: forcenoImplicitOverride: truenoUnusedLocals/noUnusedParameters: trueskipLibCheck: true
各场景差异
| 配置 | jsx | lib | module | noEmit |
|------|-----|-----|--------|--------|
| react-web | react-jsx | ES2022 + DOM | ESNext | true |
| react-native | react-jsx | ES2022(无 DOM) | ESNext | true |
| vue | preserve | ES2022 + DOM | ESNext | true |
| node | - | ES2022 | NodeNext | false(输出到 dist) |
注意
node场景使用NodeNext模块 +verbatimModuleSyntax,要求消费者项目package.json设置"type": "module"- 装饰器(
experimentalDecorators)未包含在基准中,需要时请在项目中自行开启
