There is an App class in the app:
class App {
static cart;
static init() {
const shop = new Shop();
shop.render();
this.cart = shop.cart;
}
}
I'm using VSCode as IDE and jshint as a code quality tool.
Declaring of static cart; as an App class field causes the next error message in Problems panel:
(property) App.cart: any
Class properties must be methods. Expected '(' but instead saw ';'. (E054)jshint(E054)
I tried to google for this problem, but failed.
Could you tell, please, what i am doing wrong?
I'm new to JS, so maybe there is a syntax error in my code?
It's not clear to me what your code is supposed to be doing (e.g. I don't know what Shop is/does), but I can tell you that class field definitions are allowed and are no longer experimental as of ES2022 spec.
I believe this is bug / limitation in the current version of jshint (v2.13.4 at the time of this writing) in that it does not yet recognize class fields. See https://github.com/jshint/jshint/issues/3139, which tracks the issue.
Unfortunately for the project, JSHint has had a hard time keeping pace with other tools in recent years. As described here by one of the maintainers, this was at least partly due to its clever and humorous but surprisingly problematic license agreement.
See also: