Skip to content

Conversation

@kairosci
Copy link

@kairosci kairosci commented Jan 9, 2026

Fixes #25083.

This PR relaxes the check for computed property names in type literals (specifically in isLateBindableAST) to allow ElementAccessExpression when the argument is a static literal.

Changes

  • Updated isLateBindableAST to use a new helper isLateBindableExpression.
  • isLateBindableExpression recursively checks the expression and allows:
    • String literals (e.g., Enum['key'])
    • Numeric literals
    • Signed numeric literals (e.g., Enum[-1])
    • Parenthesized expressions (e.g., Enum[('key')])

Example

enum Type {
  '3x14' = '3x14'
}
enum Numeric {
    Negative = -1,
}

type TypeMap = {
  [Type['3x14']]: any;       // Now valid
  [Numeric['Negative']]: any; // Now valid
  [Numeric[('Negative')]]: any; // Now valid
}

Verified with new test case tests/cases/compiler/enumKeysInTypeLiteral.ts covering these scenarios.

@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Jan 9, 2026
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Jan 9, 2026
@kairosci kairosci marked this pull request as draft January 9, 2026 22:07
@kairosci kairosci force-pushed the fix/enum-computed-keys branch from c7b8d77 to 3784ace Compare January 9, 2026 22:09
@kairosci kairosci marked this pull request as ready for review January 9, 2026 22:12
@kairosci kairosci changed the title Fix(checker): Allow element access expressions in computed property names if argument is literal (Fixes #25083) fix(checker): Allow element access expressions in computed property names if argument is literal Jan 9, 2026
@kairosci kairosci force-pushed the fix/enum-computed-keys branch from 3784ace to e813bb0 Compare January 9, 2026 22:25
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: Not started

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