Access to static properties via this.constructor in typescript

but in typescript this.constructor.prop causes error “TS2339: Property ‘prop’ does not exist on type ‘Function'”.

Typescript does not infer the type of constructor to be anything beyond Function (after all … the constructor might be a sub class).

So use an assertion:

class SomeClass {
    static prop = 123;
    method() {
        (this.constructor as typeof SomeClass).prop;

More on assertions

Leave a Comment