-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Bad error message for enum initializers #24210
Comments
Yeah this is a terrible and broad error message when complex non-numeric expressions are used in initializers and it needs to be fixed. |
@DanielRosenwasser Note in the second code snippet generated by the compiler: TestEnum[TestEnum["undefined"] = TestEnum.undefined] = "undefined";
|
Hi! Its fixed yet? |
What should the fix look like? |
After #50528 in TS 5.0, this bad error message is no longer present; the only error on the first code sample is:
Which makes sense, given it's self-referencing and the hover shows that. TS 3.9 fixed the second example case; the correct error now appears. |
TypeScript Version: typescript@2.9.0-dev.20180516
Search Terms: enum infinity, TS2553, enum undefined
Code 1
Expected behavior: No string valued member at all. Maybe the error message is wrong.
Actual behavior:
What does the 0 mean?
Playground Link: here
Code 2
Expected behavior: Maybe?
Actual behavior: No error at all!
So what's
TestEnum.undefined
,TestEnum.NaN
,TestEnum.Infinity
,-TestEnum.Infinity
?Playground Link: here
Related Issues:
Issue #21959: "It is a compile time error for constant enum expressions to be evaluated to NaN or Infinity."
PR #22022: "disallow nan and infinity in enum member" is made for the previous issue
I think this is not duplicated as #21959 and #22022 are talking about making undefined/NaN/Infinity an error in const enum instead of making them generate correct code in non-const enum.
The text was updated successfully, but these errors were encountered: