类定义实例成员属性,但扩展类“(匿名类)”将其定义为实例成员函数

Ale*_*lls 7 abstract-class typescript

我有这个错误:

 Class 'Entity' defines instance member property 'method', but extended class '(Anonymous class)' defines it as instance member function
Run Code Online (Sandbox Code Playgroud)

我的代码如下所示:

export abstract class Entity {

    abstract method: () => void

}

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

});
Run Code Online (Sandbox Code Playgroud)

我在github上发现了这个问题,但无法遵循推理: https ://github.com/Microsoft/TypeScript/issues/9722

有人知道这是怎么回事吗?

Ale*_*lls 10

好吧,nvm,这也回答了我的另一个问题:

export abstract class Entity {

    abstract method(): void // <--- this needs to be method not (arrow) function

}

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

});
Run Code Online (Sandbox Code Playgroud)