Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52971,8 +52971,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function checkGrammarForInvalidDynamicName(node: DeclarationName, message: DiagnosticMessage) {
// Even non-bindable names are allowed as late-bound implied index signatures so long as the name is a simple `a.b.c` type name expression
if (isNonBindableDynamicName(node) && !isEntityNameExpression(isElementAccessExpression(node) ? skipParentheses(node.argumentExpression) : (node as ComputedPropertyName).expression)) {
return grammarErrorOnNode(node, message);
if (isNonBindableDynamicName(node)) {
// Allow element access expressions with string/number literal arguments on entity name expressions
// This enables enum member references like `Type['3x14']` to be used as computed property names
if (isElementAccessExpression(node)) {
if (isStringOrNumberLiteralExpression(node.argumentExpression) && isEntityNameExpression(node.expression)) {
return;
}
}
if (!isEntityNameExpression(isElementAccessExpression(node) ? skipParentheses(node.argumentExpression) : (node as ComputedPropertyName).expression)) {
return grammarErrorOnNode(node, message);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @strict: true
// @noEmit: true

// Repro from #25083

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

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

const x: TypeMap = {
[Type.Foo]: 1,
[Type['3x14']]: 2
};