-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Fix #25083: Allow bracket notation for enum keys in computed properties #62978
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 #25083: Allow bracket notation for enum keys in computed properties #62978
Conversation
… properties This commit fixes an issue where using bracket notation to access enum members (e.g., Type['key']) was not accepted in computed property names of type literals, even though dot notation (e.g., Type.key) worked fine. The problem was in the isLateBindableAST function in checker.ts, which only accepted EntityNameExpression. Element access expressions like Type['key'] were rejected even though they resolve to the same literal type as their dot notation equivalents. Changes: - Modified isLateBindableAST to accept ElementAccessExpression when the base object is an EntityNameExpression - This enables bracket notation for accessing enum members with non-identifier names (e.g., '3x14' or names starting with digits) - Added comprehensive test case covering various scenarios including identifier and non-identifier enum keys with bracket notation Fixes microsoft#25083 Signed-off-by: Rodrigo Sanchez <[email protected]>
|
@RodrigoSanchezDev 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”),
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes issue #25083 by enabling bracket notation (Type['key']) for enum members in computed property names within type literals, making it consistent with the existing dot notation (Type.key).
Changes:
- Modified
isLateBindableASTto acceptElementAccessExpressionwhen the base is anEntityNameExpression - Added comprehensive test coverage for both identifier and non-identifier enum keys using bracket notation
Update reference baselines for the new test case that demonstrates bracket notation working correctly with enum keys in computed properties. Signed-off-by: Rodrigo Sanchez <[email protected]>
Fixes #25083
This PR enables bracket notation (e.g., Type['key']) to work alongside dot notation (Type.key) when using enum members as computed property names in type literals.
Problem: Bracket notation was rejected even though it resolves to the same literal type.
Solution: Modified isLateBindableAST to accept ElementAccessExpression when the base is an EntityNameExpression.
Testing: Added comprehensive test case covering identifier and non-identifier enum keys.
This makes TypeScript more consistent by treating Type.Foo and Type['Foo'] equivalently in computed property contexts.