Skip to content

Allow element access on enum as computed property name in type literal#63526

Closed
driphtyio wants to merge 2 commits into
microsoft:mainfrom
driphtyio:main
Closed

Allow element access on enum as computed property name in type literal#63526
driphtyio wants to merge 2 commits into
microsoft:mainfrom
driphtyio:main

Conversation

@driphtyio
Copy link
Copy Markdown
Contributor

Fixes #25083

Problem

Enum keys with non-identifier names (e.g., '3x14') cannot be used as computed property keys in type literals because bracket access (Type['3x14']) produces an ElementAccessExpression node that isLateBindableAST() does not recognize.

Reproduction

enum Type {
  Foo = 'foo',
  '3x14' = '3x14'
}

type TypeMap = {
  [Type.Foo]: any
  [Type['3x14']]: any  // Error 1170
}

Fix

3-line addition to isLateBindableAST() in src/compiler/checker.ts: when the expression is an ElementAccessExpression with a string literal argument on an entity name, treat it as late-bindable.

Properties

  • Minimal: 3 lines added
  • Only expands acceptance (never rejects previously accepted code)
  • Fixes a Good First Issue labeled Bug in the Backlog milestone

Copilot AI review requested due to automatic review settings June 2, 2026 05:48
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Jun 2, 2026
@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug labels Jun 2, 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

Note

Copilot was unable to run its full agentic suite in this review.

Updates documentation wording and broadens the TypeScript checker’s definition of “late-bindable” AST nodes to include a specific element-access pattern.

Changes:

  • Clarify Set.size JSDoc wording in es2015.collection.d.ts.
  • Extend isLateBindableAST to treat Entity["prop"] (string-literal element access off an entity name) as late-bindable.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
src/lib/es2015.collection.d.ts Small JSDoc wording tweak for Set.size.
src/compiler/checker.ts Expands late-bindable detection logic for additional AST form.
Comments suppressed due to low confidence (1)

src/compiler/checker.ts:1

  • The mixed || / && expression relies on operator precedence, which is easy to misread and error-prone during future edits (especially with the line break). Add explicit parentheses (or assign the element-access sub-check to a well-named boolean) to make the intended grouping unambiguous.

@RyanCavanaugh
Copy link
Copy Markdown
Member

This doesn't meet the 6.0 patch bar #62963 (comment)

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Jun 2, 2026
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

4 participants