microsoft / microsoft/TypeScript

Default values for jsconfig.json override extended values

未关闭
#36,682 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Domain: Something Else
主要语言
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:

  • allowJs
  • maxNodeModuleJsDepth
  • allowSyntheticDefaultImports
  • skipLibCheck
  • noEmit

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 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

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。