Skip to content

Port #63038: Consult referenced project options for synthetic default export eligibility#2752

Merged
jakebailey merged 2 commits intomainfrom
copilot/fix-synthetic-default-export-eligibility
Feb 12, 2026
Merged

Port #63038: Consult referenced project options for synthetic default export eligibility#2752
jakebailey merged 2 commits intomainfrom
copilot/fix-synthetic-default-export-eligibility

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

When a .d.ts file is resolved via a project reference, its module format was unknown, so canHaveSyntheticDefault would permissively allow synthetic defaults. This meant import Foo from './lib' against an ESM project reference with only named exports produced no error.

Changes

  • internal/checker/checker.go: In canHaveSyntheticDefault, when GetImpliedNodeFormatForEmit returns no result for a declaration file, check whether the file originates from a project reference via GetRedirectForResolution or GetProjectReferenceFromOutputDts. If so, use GetEmitModuleFormatOfFile to resolve the module kind from the referenced project's options and deny synthetic defaults when both sides are ESM.
if targetMode == core.ModuleKindNone && file.AsSourceFile().IsDeclarationFile {
    if c.program.GetRedirectForResolution(file.AsSourceFile()) != nil || c.program.GetProjectReferenceFromOutputDts(file.AsSourceFile().Path()) != nil {
        targetModuleKind := c.program.GetEmitModuleFormatOfFile(file.AsSourceFile())
        if usageMode == core.ModuleKindESNext && core.ModuleKindES2015 <= targetModuleKind && targetModuleKind <= core.ModuleKindESNext {
            return false
        }
    }
}
  • internal/execute/tsctests/tsc_test.go: Added test case "referenced project with esnext module disallows synthetic default imports".
  • Baselines: Updated 2 existing baselines and added 1 new baseline, all consistent with the TypeScript submodule expectations.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…thetic default export eligibility

In canHaveSyntheticDefault, when GetImpliedNodeFormatForEmit returns no
result for a declaration file, check if the file comes from a project
reference. If so, use GetEmitModuleFormatOfFile to determine the module
format from the referenced project's compiler options. When the usage is
ESM and the target module kind is in the ES2015-ESNext range, deny
synthetic defaults.

Also adds a new test case "referenced project with esnext module
disallows synthetic default imports" and updates affected baselines.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix consult referenced project options for synthetic default export Port #63038: Consult referenced project options for synthetic default export eligibility Feb 11, 2026
Copilot AI requested a review from jakebailey February 11, 2026 00:54
@DanielRosenwasser
Copy link
Member

@jakebailey jakebailey marked this pull request as ready for review February 12, 2026 18:01
Copilot AI review requested due to automatic review settings February 12, 2026 18:01
@jakebailey jakebailey added this pull request to the merge queue Feb 12, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports TypeScript PR #63038 to ensure synthetic default imports are not permitted when importing a declaration file that comes from an ESM project reference, by consulting the referenced project’s emit module format.

Changes:

  • Updated Checker.canHaveSyntheticDefault to consult referenced project compiler options (via project reference mapping) when implied node format can’t be determined for a .d.ts.
  • Added a new project-references tsc test case covering module: esnext referenced projects and synthetic default imports.
  • Updated/added tsc/tsbuild baselines to reflect the corrected TS1192 diagnostics and downstream type changes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/checker/checker.go Tightens canHaveSyntheticDefault by inferring module kind from referenced project options for redirected .d.ts files.
internal/execute/tsctests/tsc_test.go Adds a focused regression test for ESM project references disallowing synthetic default imports.
testdata/baselines/reference/tsc/projectReferences/referenced-project-with-esnext-module-disallows-synthetic-default-imports.js New baseline demonstrating TS1192 errors for default imports from ESM project reference outputs.
testdata/baselines/reference/tsc/projectReferences/default-import-interop-uses-referenced-project-settings.js Baseline updated to include the new TS1192 errors for referenced project imports.
testdata/baselines/reference/tsbuild/javascriptProjectEmit/loads-js-based-projects-with-non-moved-json-files-and-emits-them-correctly.js Baseline updated to reflect TS1192 + resulting any types and updated tsbuildinfo diagnostics.

Comment on lines +14471 to +14474
// Try to get the project reference - try both source file mapping and output file mapping
// since declaration files can be mapped either way depending on how they're resolved
if c.program.GetRedirectForResolution(file.AsSourceFile()) != nil || c.program.GetProjectReferenceFromOutputDts(file.AsSourceFile().Path()) != nil {
// This is a declaration file from a project reference, so we can determine
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetProjectReferenceFromOutputDts(...) != nil check appears redundant here: Program.GetRedirectForResolution already consults both the source-to-output and output-dts-to-source project reference maps (and symlink mapping). Dropping the extra lookup would simplify the condition and avoid implying there are two independent mechanisms to check.

Copilot uses AI. Check for mistakes.
Merged via the queue into main with commit 985bb98 Feb 12, 2026
27 checks passed
@jakebailey jakebailey deleted the copilot/fix-synthetic-default-export-eligibility branch February 12, 2026 18:17
Copilot AI added a commit that referenced this pull request Feb 25, 2026
… export eligibility (#2752)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants