-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cli): 更新内置默认模板 tsconfig.json
#15417
Open
anyesu
wants to merge
3
commits into
NervJS:3.x
Choose a base branch
from
anyesu:fix/tsconfig
base: 3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+10
−11
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #15417 +/- ##
=======================================
Coverage 58.51% 58.51%
=======================================
Files 491 491
Lines 21891 21891
Branches 5624 5624
=======================================
Hits 12810 12810
+ Misses 7916 7897 -19
- Partials 1165 1184 +19
Flags with carried forward coverage won't be shown. Click here to find out more. |
This was referenced Apr 1, 2024
This was referenced Apr 6, 2024
This was referenced Jul 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
这个 PR 做了什么? (简要描述所做更改)
skipLibCheck
通常情况下我们不需要关心第三方库的 TS 语法问题, 所以非常建议开启这个选项以屏蔽一些无关紧要的错误 。
需要注意的是,这个选项只会忽略
.d.ts
文件,如果第三方库包含了.ts
文件还是会继续检查错误的:typeRoots
默认情况下,所有 @types 包下( 包括上层
node_modules
)的类型定义会在编译过程中被包含进来,显式配置这个选项后就会将这个范围收缩在一个有限的范围之内。 除非有特殊需求,否则不需要配置这个选项,因为默认行为已经很好了。配置
typeRoots
会导致需要手动添加一堆目录:引入 sass 后会出现下面的错误:
这是因为
TS@5.1
引入一个重大变更:指定了typeRoots
选项但对任何typeRoots
目录的解析失败时,不再向上遍历node_modules
进行解析了。 👉 官方文档@types/sass 最新版本是一个空包,会解析失败,就不再继续从 sass 包查找了。
typeRoots
和types
常被滥用于屏蔽第三方库的错误,正确的姿势应该是开启skipLibCheck
选项并补全缺失的类型定义。noEmit
默认情况下 tsc 命令会将编译结果输出为文件( 例如
.js
、.d.ts
、.map
),这在开发 lib 项目时非常有用,但是对非 lib 项目来说是没用的,因为通常会用到 Webpack 、 Babel 之类的工具来转换源码。建议开启这个选项,这样 tsc 命令仅用于检查 TS 语法问题。
declaration
生成与源码对应的
.d.ts
文件,通常只有开发 lib 项目的时候才需要开启这个选项。已知的问题:使用 pnpm 安装依赖后,间接依赖的项目( 幽灵依赖 )没有被包含在
node_modules
中,这会导致生成.d.ts
文件时报错。( 参考 )IDEA 进行语法校验用到下面的命令,同样会报错:
建议非 lib 项目关闭这个选项。
preserveConstEnums
源码:
"preserveConstEnums": false
的编译结果:"preserveConstEnums": true
的编译结果:对于使用
const enum
关键字定义的枚举类型Album
,会在编译时将所有的枚举值Album.xxx
替换为实际的字面量。默认会擦除生成的常量对象Album
,如果开启了preserveConstEnums
则不擦除。因为
enum
加了const
关键字后枚举类整体就不能当作一个对象来使用了,只能使用具体的枚举值。所以这个选项的意义只是为了查看源码,并不影响实际代码,没必要启用。
removeComments
sourceMap
作为非 lib 项目,并不需要关心 tsc 的编译产物,所以
removeComments
、sourceMap
这些配置都是多余的。noUnusedLocals
noUnusedParameters
检测在代码中声明了但未使用的局部变量,这些配置是多余的,因为这是 ESLint 的工作。
其他
基础配置从 @tsconfig/recommended 进行复制。
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台: