Commit 10c4c32
committed
fix: allow enum member references with non-identifier names as computed property names in type literals
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!1 parent 77ddb5b commit 10c4c32
2 files changed
Lines changed: 30 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52971 | 52971 | | |
52972 | 52972 | | |
52973 | 52973 | | |
52974 | | - | |
52975 | | - | |
| 52974 | + | |
| 52975 | + | |
| 52976 | + | |
| 52977 | + | |
| 52978 | + | |
| 52979 | + | |
| 52980 | + | |
| 52981 | + | |
| 52982 | + | |
| 52983 | + | |
| 52984 | + | |
52976 | 52985 | | |
52977 | 52986 | | |
52978 | 52987 | | |
| |||
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
0 commit comments