mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 22:51:17 -05:00
Disallow Infinity, -Infinity and NaN as an enum key name (#56161)
This commit is contained in:
@@ -45022,7 +45022,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
else {
|
||||
const text = getTextOfPropertyName(member.name);
|
||||
if (isNumericLiteralName(text) && !isInfinityOrNaNString(text)) {
|
||||
if (isNumericLiteralName(text)) {
|
||||
error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
enumWithInfinityProperty.ts(2,5): error TS2452: An enum member cannot have a numeric name.
|
||||
|
||||
|
||||
==== enumWithInfinityProperty.ts (1 errors) ====
|
||||
enum A {
|
||||
Infinity = 1
|
||||
~~~~~~~~
|
||||
!!! error TS2452: An enum member cannot have a numeric name.
|
||||
}
|
||||
|
||||
10
tests/baselines/reference/enumWithNaNProperty.errors.txt
Normal file
10
tests/baselines/reference/enumWithNaNProperty.errors.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
enumWithNaNProperty.ts(2,5): error TS2452: An enum member cannot have a numeric name.
|
||||
|
||||
|
||||
==== enumWithNaNProperty.ts (1 errors) ====
|
||||
enum A {
|
||||
NaN = 1
|
||||
~~~
|
||||
!!! error TS2452: An enum member cannot have a numeric name.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
enumWithNegativeInfinityProperty.ts(2,5): error TS2452: An enum member cannot have a numeric name.
|
||||
|
||||
|
||||
==== enumWithNegativeInfinityProperty.ts (1 errors) ====
|
||||
enum A {
|
||||
"-Infinity" = 1
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2452: An enum member cannot have a numeric name.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user