Search code examples
typescriptabstract-class

Class defines instance member property, but extended class '(Anonymous class)' defines it as instance member function


I have this error:

🔴 Class 'Entity' defines instance member property 'method', but extended class '(Anonymous class)' defines it as instance member function

My code looks like:

export abstract class Entity {

    abstract method: () => void

}

const e = new (class extends Entity {
    method(): void {
        return;
    }

});

I found this issue on github but couldn't follow the reasoning: https://github.com/Microsoft/TypeScript/issues/9722

anyone know what's going on here?


Solution

  • Well nvm, this answers my other question too:

    export abstract class Entity {
    
        abstract method(): void // <--- this needs to be method not (arrow) function
    
    }
    
    const e = new (class extends Entity {
        method(): void {
            return;
        }
    
    });