mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-10 00:20:22 -06:00
fix(checker): report error when using bigint as enum key (#61777)
This commit is contained in:
parent
a591ca3fdc
commit
ac03ba4f02
@ -481,6 +481,7 @@ import {
|
||||
isAssignmentTarget,
|
||||
isAutoAccessorPropertyDeclaration,
|
||||
isAwaitExpression,
|
||||
isBigIntLiteral,
|
||||
isBinaryExpression,
|
||||
isBinaryLogicalOperator,
|
||||
isBindableObjectDefinePropertyCall,
|
||||
@ -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)) {
|
||||
|
||||
10
tests/baselines/reference/enumWithBigint.errors.txt
Normal file
10
tests/baselines/reference/enumWithBigint.errors.txt
Normal file
@ -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
tests/baselines/reference/enumWithBigint.js
Normal file
13
tests/baselines/reference/enumWithBigint.js
Normal file
@ -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
tests/baselines/reference/enumWithBigint.symbols
Normal file
10
tests/baselines/reference/enumWithBigint.symbols
Normal file
@ -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
tests/baselines/reference/enumWithBigint.types
Normal file
14
tests/baselines/reference/enumWithBigint.types
Normal file
@ -0,0 +1,14 @@
|
||||
//// [tests/cases/compiler/enumWithBigint.ts] ////
|
||||
|
||||
=== enumWithBigint.ts ===
|
||||
enum E {
|
||||
>E : E
|
||||
> : ^
|
||||
|
||||
0n = 0,
|
||||
>0n : E.__missing
|
||||
> : ^^^^^^^^^^^
|
||||
>0 : 0
|
||||
> : ^
|
||||
}
|
||||
|
||||
3
tests/cases/compiler/enumWithBigint.ts
Normal file
3
tests/cases/compiler/enumWithBigint.ts
Normal file
@ -0,0 +1,3 @@
|
||||
enum E {
|
||||
0n = 0,
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user