Skip to content

Fix invalid export default namespace in declaration emit for expandos on JS export default class - #65733

Open
Ryan Cavanaugh (RyanCavanaugh) wants to merge 4 commits into
mainfrom
copilot/fix-declaration-emit-syntax-error
Open

Ryan Cavanaugh (RyanCavanaugh) wants to merge 4 commits into
mainfrom
copilot/fix-declaration-emit-syntax-error

Conversation

@RyanCavanaugh

@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

In JS, a property assigned to a default-exported class (an expando) made declaration emit produce export default namespace X, which is a syntax error. Because it is a syntax error, skipLibCheck doesn't suppress it, so every consumer of such a .d.ts fails to type-check. This regressed from 6.0.

export default class Holidays {}
Holidays.normalize = function (country) { return country.toUpperCase() }

Before:

export default class Holidays {}
export default namespace Holidays {   // TS1005
    var normalize: (country: any) => any;
}

After:

declare class Holidays {}
export default Holidays;
declare namespace Holidays {
    var normalize: (country: any) => any;
}

Cause

createFullExpandoBlock copies the host's modifiers onto the synthesized namespace. transformExpandoHost already handles default-exported function hosts: it emits declare function f plus export default f;. Class hosts went through the generic else branch, so they kept export default, and the namespace got a copy of it.

Change (transformExpandoHost)

  • New branch for defaultExport && IsClassDeclaration. It transforms the class as usual, then replaces the class's modifiers with the computed declare modifiers.
  • The synthesized X_base variable emitted for extends <expression> is kept.
  • The branch then goes through the shared tail used by function hosts: it appends export default X;, sets the external-module and scope-marker flags, and refreshes lateStatementReplacementMap.
  • reportExpandoFunctionErrors is still skipped for classes, as before. Its isolatedDeclarations message is specific to functions.

Test

declarationEmitJsDefaultExportClassExpando.ts covers:

  • a plain expando;
  • an expando assigned from an identifier, emitted as export { helper };
  • an extends mixin(Root) host.

The first commit's baseline records the bug in the DtsFileErrors section; the fix commit removes it. No other baselines change.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug and removed For Milestone Bug PRs that fix a bug with a specific milestone labels Nov 30, 2026
… emit

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
…port default`

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) changed the title [WIP] Fix declaration emit syntax error for expando members Nov 30, 2026
@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) marked this pull request as ready for review November 30, 2026 20:10
Copilot AI balanced review requested due to automatic review settings November 30, 2026 20:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues blocking approval.

No open issues 🎉

What changed in this PR

Fixes #65731 by correcting declaration emit for JavaScript default-exported classes with expando properties, preventing invalid export default namespace syntax in generated .d.ts files.

Changes:

  • Emits the class with declare and a separate default export while preserving synthesized base declarations.
  • Adds regression coverage for plain expandos, helper aliases, and expression-based inheritance.
  • Adds declaration-output, type, and symbol baselines.
File Description
tsc/​testdata/​tests/​cases/​compiler/​declarationEmitJsDefaultExportClassExpando.ts Tests three expando scenarios and their imports.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitJsDefaultExportClassExpando.types Records inferred types for the regression cases.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitJsDefaultExportClassExpando.symbols Records symbol bindings for the regression cases.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitJsDefaultExportClassExpando.js Records corrected declaration output.
tsc/​internal/​transformers/​declarations/​transform.go Handles default-exported class expandos with valid declaration modifiers.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

3 participants