Repository navigation
Allow expando assignments to merge with same-named type-only namespace members - #65603
Open
Ryan Cavanaugh (RyanCavanaugh) wants to merge 13 commits into
Open
Ryan Cavanaugh (RyanCavanaugh) wants to merge 13 commits into
Ryan Cavanaugh (RyanCavanaugh) wants to merge 13 commits into
Conversation
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>
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>
Contributor
There was a problem hiding this comment.
🟢 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
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.
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:
Changes
bindDeferredExpandoAssignment): the expando is now also declared when the existing symbol has neitherValuenorAliasflags.PropertyExcludesonly excludes values, so the property merges cleanly with type aliases, interfaces and uninstantiated namespaces.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 emitf.a = TypesOnly;, which throws at runtime.transformExpandoAssignment), for paths the binder change makes reachable:f.a = C): the alias formexport { C as a }re-exports every meaning ofC, which conflicts with the type-onlya(TS2484). When the expando symbol also has a type or namespace meaning, emit now falls back tovar a: typeof C, as 6.0 does.export { … }member and a later var-form expando gets a generated local name. That local was emitted asexport var _a, which made_aa public member even though it doesn't exist at runtime. The local is now private and exported only asexport { _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.Tests
expandoFunctionTypeOnlyNamespaceMember.tscovers:declarationEmitExpandoTypeOnlyNamespaceMember.tscovers:The emitted
.d.tshas no errors.