When useDefineForClassFields:true
is used, the code below becomes invalid when targeting es2022
:
Cannot read properties of undefined (reading 'array')
class Bar {
array = new Array();
}
class Foo {
foo = this.bar.array; // Property 'bar' is used before its initialization
constructor(private bar: Bar) {}
}
console.log(new Foo(new Bar()))
Is there an ESLint rule that can flag this as an error?
PS: Although setting the target to EsNext
triggers an error, I am looking for a different solution.