-
Notifications
You must be signed in to change notification settings - Fork 12.8k
const enum: numeric name #3572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Well, enums can't have numeric names and |
typeof "NaN" === "string" ? |
An enum is indexed with strings not numeric things:
|
Hmmm interesting: const enum foo {
const, // valid
let, // valid
var, // valid
typeof, // valid
'Hello', // valid
'1', // error: An enum member can not have a numeric name
'NaN', // error: An enum member can not have a numeric name
'Infinity' // error: An enum member can not have a numeric name
} |
This has nothing to do with enum E {
A = NaN,
NaN = 10,
}
E[0/0]; Basically what we look for is whether the abstract operation Whether or not it matters for |
@DanielRosenwasser But NaN can't be assigned to a const enum |
It also isn't a valid value for ambient/declared enums:
|
I was writing this code:
|
That is a decent use case, but I'd still rather not have const enum rules deviate too much from enum rules. Perhaps others can weigh in. @vladima and @mhegazy might have more insight as to why
I don't believe it should be; declaring an enum implies that there exists a variable with the same mapping semantics at runtime. |
We disallow We could reasonably remove that restriction for identifier-like things because it's very unlikely you would actually have an enum member whose value was one of those non-real numbers. |
If you mean for all enums, I don't see why, since we've already settled on a reasonably consistent semantics. If you mean for const enums, I feel like that would introduce more inconsistencies between the two which is undesirable. |
Don't think those should be errors.
The text was updated successfully, but these errors were encountered: