Fix: Allow enum keys with non-identifier names in computed properties#62647
Closed
atsushi196323 wants to merge 2 commits intomicrosoft:mainfrom
Closed
Fix: Allow enum keys with non-identifier names in computed properties#62647atsushi196323 wants to merge 2 commits intomicrosoft:mainfrom
atsushi196323 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
… (issue microsoft#25083) Support element access expressions (e.g., Type['key']) in computed property names, allowing enums with non-identifier keys like '3x14' and 'hello-world' to work correctly with bracket notation. Tests added to verify the fix works with various enum key formats.
The previous implementation allowed any element access expression in computed property names, which caused issues with other type checking scenarios. This fix restricts element access expressions (e.g., Type['key']) to only work when: - The object is a direct identifier (enum name) - The key is a string literal This allows enums with non-identifier keys like '3x14' and 'hello-world' to work with bracket notation, while maintaining proper type checking for other element access patterns. Fixes issue microsoft#25083
Author
|
@microsoft-github-policy-service agree |
Collaborator
|
With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies). Next steps for PRs:
|
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.
Summary
This PR fixes issue #25083 by enabling enum keys with non-identifier names (like
'3x14'and'hello-world') to work in computed property names using bracket notation.Type['key']) in computed property namesisEntityNameElementAccess()helper function to validate element access patternsChanges
isLateBindableAST()insrc/compiler/checker.tsto recognize element access expressionsisEntityNameElementAccess()to validate bracket notation access patternsTest Plan
enumComputedPropertyNonIdentifier.tscovering:'3x14'and'hello-world'All baselines verified:
.types- Type information correct.symbols- Symbol resolution working.js- Compiled output valid