Fix declaration emit synthesizing extensionless import() specifier under allowImportingTsExtensions + nodenext - #4662
Merged
RyanCavanaugh merged 1 commit intoJul 17, 2026
Conversation
…nsions When a file uses `.ts`-extension relative imports (allowImportingTsExtensions), declaration emit was synthesizing extensionless import() specifiers for non-relative (node_modules) module references, which is invalid under nodenext. Root cause: GetAllowedEndingsInPreferredOrder used syntaxImpliedNodeFormat directly without falling back to the file's implied format when it's None. TypeScript 6 uses (syntaxImpliedNodeFormat ?? impliedNodeFormat), properly falling back to the ESM file's implied mode. This caused the wrong allowedEndings ordering ([TsExtension, Minimal, JsExtension, ...] instead of [TsExtension, JsExtension]), which led processEnding to return extensionless paths for .d.ts files. The fix adds the same fallback: when syntaxImpliedNodeFormat is ResolutionModeNone, use resolutionMode (the file's default) for the ESM+NodeNext check. Fixes microsoft#4616 Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes declaration emit to preserve .js package subpath extensions under NodeNext when TypeScript-extension imports are allowed.
Changes:
- Falls back to the file’s resolution mode when no syntax-implied mode exists.
- Adds regression coverage and declaration/type/symbol baselines.
Show a summary per file
| File | Description |
|---|---|
internal/modulespecifiers/preferences.go |
Implements the upstream resolution-mode fallback. |
testdata/tests/cases/compiler/declarationEmitImportSpecifierWithTsExtensionRelativeImport.ts |
Adds the regression scenario. |
testdata/baselines/reference/compiler/declarationEmitImportSpecifierWithTsExtensionRelativeImport.js |
Verifies .js in declaration emit. |
testdata/baselines/reference/compiler/declarationEmitImportSpecifierWithTsExtensionRelativeImport.types |
Records inferred types. |
testdata/baselines/reference/compiler/declarationEmitImportSpecifierWithTsExtensionRelativeImport.symbols |
Records symbols. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0
- Review effort level: Medium
Member
Author
|
This is a redo of #4649 but now GitHub API is down 🙁 |
andrewbranch
approved these changes
Jul 16, 2026
RyanCavanaugh
deleted the
copilot/fix-import-extension-issue-author-fix-mro2e0m9
branch
July 17, 2026 19:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When using
allowImportingTsExtensions: truewith.ts-extension relative imports undermodule: nodenext, declaration emit was generating invalid extensionlessimport()type references for node_modules packages —import("mylib/lib/Box")instead ofimport("mylib/lib/Box.js")— causingTS2307errors in the emitted.d.ts.Root cause
GetAllowedEndingsInPreferredOrderinpreferences.gochecked the ESM+NodeNext special case as:TypeScript 6 uses
(syntaxImpliedNodeFormat ?? impliedNodeFormat), falling back to the file's implied node format whensyntaxImpliedNodeFormatis not provided. The Go port was missing this fallback.When
tryGetModuleNameAsNodeModulecalls withResolutionModeNone, the ESM check was alwaysfalse, yielding[TsExtension, Minimal, JsExtension, Index]instead of the correct[TsExtension, JsExtension]. WithMinimalbeforeJsExtension,processEndingpicked the extensionless form for.d.tsdeclaration files.Fix
internal/modulespecifiers/preferences.go: WhensyntaxImpliedNodeFormatisResolutionModeNone, fall back toresolutionMode(the file's default) before the ESM+NodeNext check — matching TypeScript's??semantics.testdata/tests/cases/compiler/declarationEmitImportSpecifierWithTsExtensionRelativeImport.ts: Regression test covering the exact repro: ESM package,.ts-extension relative import chain, node_modules subpath with.jsextension, verifiedmod.d.tsoutput is nowimport("mylib/lib/Box.js").Box<string>with noTS2307.import()specifier underallowImportingTsExtensions, invalid in nodenext #4616