Skip to content
Open
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
2 changes: 1 addition & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23787,7 +23787,7 @@ func (c *Checker) getDeclaredTypeOfEnum(symbol *ast.Symbol) *Type {
for _, declaration := range symbol.Declarations {
if declaration.Kind == ast.KindEnumDeclaration {
for _, member := range declaration.Members() {
if c.hasBindableName(member) {
if !ast.HasDynamicName(member) {
memberSymbol := c.getSymbolOfDeclaration(member)
value := c.getEnumMemberValue(member).Value
var memberType *Type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
computedEnumMemberKeyNoCrash1.ts(4,5): error TS1164: Computed property names are not allowed in enums.


==== computedEnumMemberKeyNoCrash1.ts (1 errors) ====
// https://github.com/microsoft/TypeScript/issues/63173

declare const enum E {
[foo] = 1,
~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
A,
foo = 10,
}
E.A.toString();

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [tests/cases/compiler/computedEnumMemberKeyNoCrash1.ts] ////

=== computedEnumMemberKeyNoCrash1.ts ===
// https://github.com/microsoft/TypeScript/issues/63173

declare const enum E {
>E : Symbol(E, Decl(computedEnumMemberKeyNoCrash1.ts, 0, 0))

[foo] = 1,
>[foo] : Symbol(E[foo], Decl(computedEnumMemberKeyNoCrash1.ts, 2, 22))
>foo : Symbol(E.foo, Decl(computedEnumMemberKeyNoCrash1.ts, 4, 6))

A,
>A : Symbol(E.A, Decl(computedEnumMemberKeyNoCrash1.ts, 3, 14))

foo = 10,
>foo : Symbol(E.foo, Decl(computedEnumMemberKeyNoCrash1.ts, 4, 6))
}
E.A.toString();
>E.A.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
>E.A : Symbol(E.A, Decl(computedEnumMemberKeyNoCrash1.ts, 3, 14))
>E : Symbol(E, Decl(computedEnumMemberKeyNoCrash1.ts, 0, 0))
>A : Symbol(E.A, Decl(computedEnumMemberKeyNoCrash1.ts, 3, 14))
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [tests/cases/compiler/computedEnumMemberKeyNoCrash1.ts] ////

=== computedEnumMemberKeyNoCrash1.ts ===
// https://github.com/microsoft/TypeScript/issues/63173

declare const enum E {
>E : E

[foo] = 1,
>[foo] : E
>foo : E.foo
>1 : 1

A,
>A : E.A

foo = 10,
>foo : E.foo
>10 : 10
}
E.A.toString();
>E.A.toString() : string
>E.A.toString : (radix?: number) => string
>E.A : E.A
>E : typeof E
>A : E.A
>toString : (radix?: number) => string

11 changes: 11 additions & 0 deletions testdata/tests/cases/compiler/computedEnumMemberKeyNoCrash1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @strict: true
// @noEmit: true

// https://github.com/microsoft/TypeScript/issues/63173

declare const enum E {
[foo] = 1,
A,
foo = 10,
}
E.A.toString();