Skip to content

Default values for jsconfig.json override extended values #36682

@yo1dog

Description

@yo1dog

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Something ElseFallback label when we just can't figure anything else out

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions