Skip to content

Potentially wrong 'showConfig' results for default values, as it's used in the checker differently.Β #59442

@chwoerz

Description

@chwoerz

πŸ”Ž Search Terms

"showConfig result moduleResolution wrong"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about showConfig

⏯ Playground Link

No response

πŸ’» Code

tsconfig:

{
  "compilerOptions": {
  }
}

cli call:
tsc --showConfig

πŸ™ Actual behavior

{    
  "compilerOptions": {}
}

πŸ™‚ Expected behavior

Wanted Output from tsc --showConfig

{
  "compilerOptions": {
    "moduleResolution": "Node10",
    // And All other fields which have default values
  }
}

Explanation

When we check utilities.ts: 8859 computedOptions we can see, that this moduleResolution has the following computeValue functionality and that its not the default value because it depends on the computed module value which is, if not set, commonjs.

{
dependencies: ["module", "target"],
  computeValue: (compilerOptions): ModuleResolutionKind => {
  let moduleResolution = compilerOptions.moduleResolution;
  if (moduleResolution === undefined) {
    switch (computedOptions.module.computeValue(compilerOptions)) {
      case ModuleKind.CommonJS:
        moduleResolution = ModuleResolutionKind.Node10;
        break;
      case ModuleKind.Node16:
        moduleResolution = ModuleResolutionKind.Node16;
        break;
      case ModuleKind.NodeNext:
        moduleResolution = ModuleResolutionKind.NodeNext;
        break;
      case ModuleKind.Preserve:
        moduleResolution = ModuleResolutionKind.Bundler;
        break;
      default:
        moduleResolution = ModuleResolutionKind.Classic;
        break;
    }
  }
  return moduleResolution;
},
    }

And in the compiler, it's used like this:

export const getEmitModuleResolutionKind = computedOptions.moduleResolution.computeValue;
// Usage:
getEmitModuleResolutionKind(compilerOptions)

So there is no checking for if the dependencies are used. So this means that the default value will be used even if there is no dependency specified in the tsconfig.

But in the showConfig code (commandLineParser.ts: 2565) we can see, that it checks if some of it's dependencies are there:

if (!providedKeys.has(option) && some(computedOptions[option as keyof typeof computedOptions].dependencies, dep => providedKeys.has(dep))) {

Suggestion

So I think the showConfig does not show the "real" values which are used during the execution of the code and I would suggest to change that to show all the properties if they have a value which is other than undefined.

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueIn DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions