Fix declaration emit synthesizing extensionless import() specifier under allowImportingTsExtensions + nodenext#4649
Open
RyanCavanaugh with Copilot wants to merge 2 commits into
Open
Fix declaration emit synthesizing extensionless import() specifier under allowImportingTsExtensions + nodenext#4649RyanCavanaugh with Copilot wants to merge 2 commits into
RyanCavanaugh with Copilot wants to merge 2 commits into
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 #4616 Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix declaration emit for extensionless import() specifier
Fix declaration emit synthesizing extensionless import() specifier under allowImportingTsExtensions + nodenext
Jul 15, 2026
andrewbranch
approved these changes
Jul 15, 2026
andrewbranch
marked this pull request as ready for review
July 15, 2026 23:46
andrewbranch
enabled auto-merge
July 15, 2026 23:47
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a declaration emit module-specifier selection bug in the tsgo port that could synthesize extensionless import() type references under --module nodenext when allowImportingTsExtensions is enabled, leading to invalid emitted .d.ts (e.g. TS2307 due to missing .js).
Changes:
- Fix
GetAllowedEndingsInPreferredOrderto fall back fromsyntaxImpliedNodeFormatto the file’s implied/default resolution mode when the syntax-implied mode is not provided (ResolutionModeNone), matching upstream??semantics. - Add a compiler regression test reproducing the
.ts-extension relative import chain and asserting.jsis preserved in synthesizedimport()specifiers for node_modules subpaths. - Add the corresponding reference baselines for the new test.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
internal/modulespecifiers/preferences.go |
Implements the ResolutionModeNone fallback so ESM+NodeNext ending preferences are computed correctly. |
testdata/tests/cases/compiler/declarationEmitImportSpecifierWithTsExtensionRelativeImport.ts |
New regression test covering the reported nodenext + allowImportingTsExtensions declaration emit scenario. |
testdata/baselines/reference/compiler/declarationEmitImportSpecifierWithTsExtensionRelativeImport.js |
Reference baseline verifying emitted mod.d.ts contains import("mylib/lib/Box.js").... |
testdata/baselines/reference/compiler/declarationEmitImportSpecifierWithTsExtensionRelativeImport.types |
Reference types baseline for the new test case. |
testdata/baselines/reference/compiler/declarationEmitImportSpecifierWithTsExtensionRelativeImport.symbols |
Reference symbols baseline for the new test case. |
RyanCavanaugh
marked this pull request as draft
July 16, 2026 20:01
auto-merge was automatically disabled
July 16, 2026 20:01
Pull request was converted to draft
RyanCavanaugh
marked this pull request as ready for review
July 16, 2026 20:01
RyanCavanaugh
approved these changes
Jul 16, 2026
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