-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Fix: Allow enum keys with non-identifier names in computed properties #62647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix: Allow enum keys with non-identifier names in computed properties #62647
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.
|
@atsushi196323 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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
|
@microsoft-github-policy-service agree |
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