Port PR#60052: Computed names in declaration files are resolved even when non-literal, preserve computed names when expressions are entity names #1858
+145
−724
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.
This PR ports TypeScript PR#60052 to the Go codebase.
Overview
This change allows computed property names in declaration files to be resolved even when they're not literals, as long as they are entity name expressions (like
a.b.c
). Additionally, the implementation now preserves those computed names in declaration emit when possible, rather than always converting them to generic index signatures.What Changed
1. Symbol Resolution for Computed Names
The
trackComputedName
function now resolves names at theenclosingDeclaration
location first, with a fallback to thefirstIdentifier
location. This ensures correct symbol tracking when computed names are referenced across different scopes:2. Static vs Instance Index Signature Checking
Updated
checkIndexConstraints
to properly check static properties against static index signatures and instance properties against instance index signatures. Previously, only instance properties were validated against index signatures:3. Preserving Computed Names in Declaration Emit
Added
indexInfoToObjectComputedNamesOrSignatureDeclaration
function that preserves computed property names as explicit property signatures when all components are visible entity name expressions, rather than always collapsing them into generic index signatures:This provides more precise type information in declaration files while maintaining compatibility with the TypeScript compiler's behavior.
Test Results
Key tests now passing include:
declarationEmitSimpleComputedNames1
declarationEmitComputedNamesInaccessible
ES5SymbolProperty1
computedPropertyNames48
Impact
This change brings the Go implementation closer to TypeScript's handling of computed property names in declaration contexts, enabling better support for:
Original prompt
Note
Custom agent used: Strada to Corsa Port Expert
A Go and TypeScript expert who can easily figure out how to port PRs from one language to another
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.