fix: tsconfig extends
supporting same extensions (inc .jsonc
) for relative and package imports (bug #43121)
#62092
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #43121
This PR adds support for
.jsonc
file extensions when resolving tsconfigextends
paths through Node.js module resolution. Previously, TypeScript only supported.jsonc
files for relative paths (e.g.,"extends": "./config.jsonc"
) but failed when trying to resolve package-based extends (e.g.,"extends": "pkg/config.jsonc"
).Problem
When using
"extends": "pkg/foo.jsonc"
in a tsconfig.json, TypeScript would attempt to resolvenode_modules/pkg/foo.jsonc.json
and fail, even though the same.jsonc
file could be successfully loaded using relative paths like"extends": "./foo.jsonc"
.This inconsistency forced developers to either:
.json
extensions and deal with linter warnings about commentstsconfig*.json
files.jsonc
filesChanges
Core Resolution Changes
src/compiler/moduleNameResolver.ts
:nodeNextJsonConfigResolver
tonodeNextTsconfigResolver
Extensions.Any
instead ofExtensions.Json
. I was thinking about adding aJsonc
Extensions value, but decided against this so the behaviour of relative tsconfig and package tsconfig imports would be the same (any extensions are valid for relative imports)src/compiler/commandLineParser.ts
:Testing
Added test cases before starting, to ensure test went from failing to passing:
tests/cases/compiler/tsconfigExtendsJsoncPackage.ts
: Tests package-based.jsonc
extendstests/cases/compiler/tsconfigExtendsJsoncRelative.ts
: Ensures relative.jsonc
extends still work (regression test)Both test cases verify that:
.jsonc
config files are properly resolved and loadedinlineSourceMap: true
is setBackward Compatibility
This change is fully backward compatible:
.json
config files continue to work exactly as before.jsonc
paths that already worked remain unchanged