Skip to content

Allow expando assignments to merge with same-named type-only namespace members - #65603

Open
Ryan Cavanaugh (RyanCavanaugh) wants to merge 13 commits into
mainfrom
copilot/fix-expando-property-issue
Open

Ryan Cavanaugh (RyanCavanaugh) wants to merge 13 commits into
mainfrom
copilot/fix-expando-property-issue

Conversation

@RyanCavanaugh

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

Copy link
Copy Markdown
Member

Since microsoft/typescript-go#2715, any existing export with the same name suppresses an expando assignment, even when that export is type-only. The property is dropped and TS2339 is reported. This breaks the Mantine compound-component pattern:

function f() {}
f.a = 0;                           // 7.0: TS2339 Property 'a' does not exist on type '() => void'
namespace f { export type a = 0; } // same with an interface or an uninstantiated namespace

Changes

  • Binder (bindDeferredExpandoAssignment): the expando is now also declared when the existing symbol has neither Value nor Alias flags. PropertyExcludes only excludes values, so the property merges cleanly with type aliases, interfaces and uninstantiated namespaces.
    • Aliases (export import a = X) still suppress the expando. Allowing the merge would match 6.0's type checking, but it would also bring back 6.0's JS emit f.a = TypesOnly;, which throws at runtime.
  • Declaration emit (transformExpandoAssignment), for paths the binder change makes reachable:
    • Identifier right-hand side (f.a = C): the alias form export { C as a } re-exports every meaning of C, which conflicts with the type-only a (TS2484). When the expando symbol also has a type or namespace meaning, emit now falls back to var a: typeof C, as 6.0 does.
    • Renamed locals: suppose the host already has an export { … } member and a later var-form expando gets a generated local name. That local was emitted as export var _a, which made _a a public member even though it doesn't exist at runtime. The local is now private and exported only as export { _a as Target }. This bug predates What do we call this command-line option? #2715, but the binder change makes it reachable for the issue's Popover shape.
// Source
export function Popover() { return null; }
Popover.b = C;
Popover.Target = Target;   // Target is also a top-level function
export namespace Popover { export namespace Target { export type Extra = string; } }

// Emitted .d.ts
export declare namespace Popover {
    export { C as b };
    var _a: typeof import("./mod").Target;   // previously `export var _a`
    export { _a as Target };
}

Tests

  • expandoFunctionTypeOnlyNamespaceMember.ts covers:

    • every variant listed in the issue
    • a namespace member that contains a value, which is still an error
    • aliases to a type-only namespace and to a value namespace
    • the Popover module
  • declarationEmitExpandoTypeOnlyNamespaceMember.ts covers:

    • right-hand sides that are a class, an enum, a function, or a function merged with a namespace
    • var-form and export-form members mixed in one host
    • the renamed-local case

    The emitted .d.ts has no errors.

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

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

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

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

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) changed the title [WIP] Fix expando property loss in merged namespace exports Allow expando assignments to merge with same-named type-only namespace members Nov 20, 2026
@RyanCavanaugh

Copy link
Copy Markdown
Member Author

Copilot mcfly please

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

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

Copilot AI commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Copilot mcfly please

Restacked: 5ac41ac (revert to main) → 4e199c4 (tests + pre-fix baselines showing TS2339) → 0a106de (binder fix) → 9806e09 (declaration emit fix) → 1f6b26f (baseline updates). Final tree is identical to the pre-restack head cb2e41a.

@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) marked this pull request as ready for review November 20, 2026 18:37
Copilot AI balanced review requested due to automatic review settings November 20, 2026 18:37

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 requiring resolution for the expando-property merge and declaration-emission changes.

No open issues 🎉

What changed in this PR

Addresses #65600 by restoring function expando properties when a merged namespace exports a same-named type-only member, supporting compound-component patterns such as Popover.Target.

Changes:

  • Allows expando assignments to merge with type-only declarations while preserving precedence for values and aliases.
  • Adjusts declaration emit to avoid conflicting re-exports and keep renamed helper locals private.
  • Adds regression tests and baselines for type checking, declaration emit, and compound-component patterns.
File Description
tsc/​testdata/​tests/​cases/​compiler/​expandoFunctionTypeOnlyNamespaceMember.ts Tests type-only merges, value and alias conflicts, and Popover usage.
tsc/​testdata/​tests/​cases/​compiler/​declarationEmitExpandoTypeOnlyNamespaceMember.ts Tests declaration emit with identifier assignments and renamed locals.
tsc/​testdata/​baselines/​reference/​compiler/​expandoFunctionTypeOnlyNamespaceMember.types Records inferred expando and namespace-member types.
tsc/​testdata/​baselines/​reference/​compiler/​expandoFunctionTypeOnlyNamespaceMember.symbols Records merged symbol bindings.
tsc/​testdata/​baselines/​reference/​compiler/​expandoFunctionTypeOnlyNamespaceMember.js Records JavaScript and declaration output for merge variants.
tsc/​testdata/​baselines/​reference/​compiler/​expandoFunctionTypeOnlyNamespaceMember.errors.txt Records expected diagnostics for incompatible assignments and aliases.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitExpandoTypeOnlyNamespaceMember.types Records types for declaration-emission scenarios.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitExpandoTypeOnlyNamespaceMember.symbols Records symbol bindings for declaration-emission scenarios.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitExpandoTypeOnlyNamespaceMember.js Records declaration output without conflicting aliases or exposed helper locals.
tsc/​internal/​transformers/​declarations/​transform.go Uses variable declarations for merged members and keeps renamed locals private.
tsc/​internal/​binder/​binder.go Permits expando properties to merge with existing type-only exports.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7.0 regression: expando property on a function declaration is dropped when a merged namespace exports a type with the same name (TS2339)

3 participants