Skip to content

Fix #25083: Allow bracket notation for enum keys in computed properties#62978

Closed
RodrigoSanchezDev wants to merge 2 commits intomicrosoft:mainfrom
RodrigoSanchezDev:fix/enum-bracket-notation-computed-properties-25083
Closed

Fix #25083: Allow bracket notation for enum keys in computed properties#62978
RodrigoSanchezDev wants to merge 2 commits intomicrosoft:mainfrom
RodrigoSanchezDev:fix/enum-bracket-notation-computed-properties-25083

Conversation

@RodrigoSanchezDev
Copy link
Copy Markdown

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.

… 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 <Rodrigo@sanchezdev.com>
Copilot AI review requested due to automatic review settings January 12, 2026 20:02
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Jan 12, 2026
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Jan 12, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 isLateBindableAST to accept ElementAccessExpression when the base is an EntityNameExpression
  • 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 <Rodrigo@sanchezdev.com>
@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
@typescript-bot
Copy link
Copy Markdown
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:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Enum keys not accepted as computed properties if their name is not a valid identifier

3 participants