This piece of code transpiles with Babel and TypeScript and works as expected.
class ParentClass {
static staticProp = true;
method() {
console.log(this.constructor.staticProp);
}
}
class ChildClass extends ParentClass {
static staticProp = false;
}
(new ChildClass).method();
The requirement here is to refer to static property of current class (through this.constructor) instead of mentioning the class explicitly, so the method can be inherited and use the relevant static property in child classes.
It is ok for Babel, and TypeScript compiles it as well, but it throws
error TS2339: Property 'staticProp' does not exist on type 'Function'.
on compilation.
How can this case be treated to please TypeScript compiler?