microsoft / microsoft/TypeScript

Default values for jsconfig.json override extended values

Open
#36,682 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: Something Else
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/compiler/commandLineParser.ts at the jsconfig default-value handling referenced by the issue. Reproduce the problem with the two configs and compare npx tsc -p ... --showConfig for each. Done means explicitly defined values from an extended config are preserved rather than replaced by jsconfig defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.