Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ import {
isAssignmentTarget,
isAutoAccessorPropertyDeclaration,
isAwaitExpression,
isBigIntLiteral,
isBinaryExpression,
isBinaryLogicalOperator,
isBindableObjectDefinePropertyCall,
Expand Down Expand Up @@ -47541,6 +47542,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (isComputedNonLiteralName(member.name)) {
error(member.name, Diagnostics.Computed_property_names_are_not_allowed_in_enums);
}
else if (isBigIntLiteral(member.name)) {
error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name);
}
else {
const text = getTextOfPropertyName(member.name);
if (isNumericLiteralName(text) && !isInfinityOrNaNString(text)) {
Expand Down
10 changes: 10 additions & 0 deletions tests/baselines/reference/enumWithBigint.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
enumWithBigint.ts(2,3): error TS2452: An enum member cannot have a numeric name.


==== enumWithBigint.ts (1 errors) ====
enum E {
0n = 0,
~~
!!! error TS2452: An enum member cannot have a numeric name.
}

13 changes: 13 additions & 0 deletions tests/baselines/reference/enumWithBigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [tests/cases/compiler/enumWithBigint.ts] ////

//// [enumWithBigint.ts]
enum E {
0n = 0,
}


//// [enumWithBigint.js]
var E;
(function (E) {
E[E[0n] = 0] = 0n;
})(E || (E = {}));
10 changes: 10 additions & 0 deletions tests/baselines/reference/enumWithBigint.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [tests/cases/compiler/enumWithBigint.ts] ////

=== enumWithBigint.ts ===
enum E {
>E : Symbol(E, Decl(enumWithBigint.ts, 0, 0))

0n = 0,
>0n : Symbol(E[0n], Decl(enumWithBigint.ts, 0, 8))
}

14 changes: 14 additions & 0 deletions tests/baselines/reference/enumWithBigint.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [tests/cases/compiler/enumWithBigint.ts] ////

=== enumWithBigint.ts ===
enum E {
>E : E
> : ^

0n = 0,
>0n : E.__missing
> : ^^^^^^^^^^^
>0 : 0
> : ^
}

3 changes: 3 additions & 0 deletions tests/cases/compiler/enumWithBigint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enum E {
0n = 0,
}