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.
What I believe is going on here is that a ":" is mistakenly being used instead of a an "=".
Although it looks that way for your provided examples, it's not the case.
It might make sense to return this suggestion to the user instead of the more generic error that a comma is expected.
While I agree that the error message is not intuitive for your provided examples, if we have code such as:
enumE1{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: