Skip to content

Fix: Allow enum keys with non-identifier names in computed properties#62647

Closed
atsushi196323 wants to merge 2 commits intomicrosoft:mainfrom
atsushi196323:enum-computed-property-fix
Closed

Fix: Allow enum keys with non-identifier names in computed properties#62647
atsushi196323 wants to merge 2 commits intomicrosoft:mainfrom
atsushi196323:enum-computed-property-fix

Conversation

@atsushi196323
Copy link
Copy Markdown

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.

  • Support element access expressions (e.g., Type['key']) in computed property names
  • Add isEntityNameElementAccess() helper function to validate element access patterns
  • Allows computed properties to work with any valid enum key format

Changes

  • Modified isLateBindableAST() in src/compiler/checker.ts to recognize element access expressions
  • Added new helper function isEntityNameElementAccess() to validate bracket notation access patterns

Test Plan

  • Added comprehensive test case enumComputedPropertyNonIdentifier.ts covering:
    • Enums with non-identifier keys like '3x14' and 'hello-world'
    • Computed properties using bracket notation for these keys
    • Type inference and symbol resolution
    • JavaScript output generation

All baselines verified:

  • .types - Type information correct
  • .symbols - Symbol resolution working
  • .js - Compiled output valid

… (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
@atsushi196323
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@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

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants