-
Notifications
You must be signed in to change notification settings - Fork 12.8k
const
in class body
#4045
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
I'm a newbie but this is a result of my debugging analysis: The problem is in
How to resolve the issue? I guess it is necessary to either:
or
|
I would probably check if the current token is considered a keyword in any context and whether the subsequent token is a potential class member declaration or keyword on the same line. If so, then I would have a separate function that aggregates the invalid modifiers, reports errors on them, and returns the actual thing being declared. So for the following: class C {
public const var export foo = 10;
var constructor() { }
} I would expect:
I'm shying away from "A class member cannot have a '{0}' modifier" because it reads awkwardly if the modifier starts with a vowel. Maybe @JsonFreeman has suggestions all around. |
You could use "A class member cannot have the '{0}' modifier" |
Or specifically for the 'var' case, "A class member cannot have the '{0}' keyword." Does that sound alright? |
Yes I think so. |
We now give an error message thanks to @MartyIX. |
@MartyIX way to go! |
Hi,
I know ES6 doesn't support using const with class members and I'm assuming this is why TypeScript also does not. I'm wondering if the error if someone tries to do this with TypeScript can be improved.
In the code above, TypeScript gives the error "
'=' expected.
", twice.It would be much better to get an error such as "Class members cannot be declared with the const keyword.". Bonus points if it suggested something like, "Consider creating a module of the same name and exporting a constant from there."
The text was updated successfully, but these errors were encountered: