-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
More helpful error message for mistakenly using : instead of = in Enum #838
Comments
As of fecbdb68bd1230757cd35f63397af006926edfa5, this is the relevant call stack:
Although it looks that way for your provided examples, it's not the case.
While I agree that the error message is not intuitive for your provided examples, if we have code such as: enum E1 { a, b: any "hello" += 1, c, d} ...it becomes much less obvious what an intuitive error message should be. The error message that is provided arises because the colon aborts the enum member parsing and relinquishes back to delimited list parsing (hence the expectation of a list terminator or comma). I personally think the current behaviour is justified (based on the implementation and lack of severity of the issue), but a core team member may well have a different opinion. |
In the following test case the compiler gives an error message about expecting a comma. What I believe is going on here is that a ":" is mistakenly being used instead of a an "=". It might make sense to return this suggestion to the user instead of the more generic error that a comma is expected.
==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts (3 errors) ====
enum E2 { a, }
enum E3 { a: 1, }
!!! error TS1005: ',' expected.
enum E1 { a, b: 1, c, d: 2 = 3 }
!!! error TS1005: ',' expected.
!!! error TS1005: ',' expected.
The text was updated successfully, but these errors were encountered: