-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Description
π 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.