microsoft / microsoft/TypeScript
Default values for jsconfig.json override extended values
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
TypeScript Version: 3.8.0-dev.20200207
Search Terms: jsconfig extend override defaults
Code
// a/jsconfig.json
{
"files": ["test.js"],
"compilerOptions": {
"maxNodeModuleJsDepth": 0
}
}
// b/jsconfig.json
{
"extends": "../a/jsconfig.json"
}
// a/test.js
console.log("hello");
Reproduce
mkdir -p a b
echo '{"files":["test.js"],"compilerOptions":{"maxNodeModuleJsDepth":0}}' > a/jsconfig.json
echo '{"extends":"../a/jsconfig.json"}' > b/jsconfig.json
echo 'console.log("hello");' > a/test.js
npx tsc -p a/jsconfig.json --showConfig
npx tsc -p b/jsconfig.json --showConfig
Expected behavior:
Both implied configs A and B have compilerOptions.maxNodeModuleJsDepth: 0.
Actual behavior:
Implied config A has compilerOptions.maxNodeModuleJsDepth: 0.
Implied config B has compilerOptions.maxNodeModuleJsDepth: 2.
Output:
{
"compilerOptions": {
"allowJs": true,
"maxNodeModuleJsDepth": 0,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"noEmit": true
},
"files": [
"./test.js"
]
}
{
"compilerOptions": {
"allowJs": true,
"maxNodeModuleJsDepth": 2,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"noEmit": true
},
"files": [
"../a/test.js"
]
}
Implied config B has maxNodeModuleJsDepth: 2 despite it extending config A which explicitly sets maxNodeModuleJsDepth: 0.
Possible cause
This may be caused by the default values for config files named jsconfig.json overriding the values from the extended config. maxNodeModuleJsDepth: 2 is one of the default values. See: /src/compiler/commandLineParser.ts#L2459
Solution
Default values for jsconfig.json config files should not override values explicitly defined by the extended configs.
Workaround
Explicitly set the following values in config files named jsconfig.json that extend other configs with non-default values:
allowJsmaxNodeModuleJsDepthallowSyntheticDefaultImportsskipLibChecknoEmit
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 src/compiler/commandLineParser.ts 中 issue 提到的 jsconfig 默认值处理开始。使用两个配置复现问题,并分别比较 npx tsc -p ... --showConfig 的结果。完成的标准是:扩展配置中显式定义的值会被保留,而不是被 jsconfig 默认值替换。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 30/100