Skip to content

fix: allow enum member references with non-identifier names as computed property names#63304

Closed
cyphercodes wants to merge 1 commit intomicrosoft:mainfrom
cyphercodes:main
Closed

fix: allow enum member references with non-identifier names as computed property names#63304
cyphercodes wants to merge 1 commit intomicrosoft:mainfrom
cyphercodes:main

Conversation

@cyphercodes
Copy link

Fixes #25083

Previously, using an enum member with a non-identifier name (like '3x14') as a computed property name in a type literal would incorrectly produce an error:
'A computed property name in a type literal must refer to an expression whose type is a literal type or a unique symbol type.'

The fix updates checkGrammarForInvalidDynamicName to also allow element access expressions where:

  1. The argument expression is a string or number literal
  2. The expression being accessed is an entity name expression (like Type in Type['3x14'])

This enables patterns like:

enum Type { '3x14' = '3x14' }
type TypeMap = { [Type['3x14']]: any }  // Now works!

Test case included.

…ed property names in type literals

Fixes microsoft#25083

Previously, using an enum member with a non-identifier name (like '3x14') as a
computed property name in a type literal would incorrectly produce an error:
'A computed property name in a type literal must refer to an expression whose
type is a literal type or a unique symbol type.'

The fix updates checkGrammarForInvalidDynamicName to also allow element access
expressions where:
1. The argument expression is a string or number literal
2. The expression being accessed is an entity name expression (like Type in Type['3x14'])

This enables patterns like:
  enum Type { '3x14' = '3x14' }
  type TypeMap = { [Type['3x14']]: any }  // Now works!
@jakebailey
Copy link
Member

Sorry, but we are not accepting PRs of this kind at this time. https://github.com/microsoft/TypeScript#:~:text=NOTE%3A%20Code%20changes%20in%20this%20repo%20are%20now%20limited%20to%20a%20small%20category%20of%20fixes%3A


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

@jakebailey jakebailey closed this Mar 26, 2026
@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 26, 2026
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.

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

2 participants