调用带有原型的抽象方法

问题描述 投票:0回答:0

我有一个带有抽象方法的抽象类。我发现如果我用

prototype
call
调用方法,Typescript 不会抛出任何错误。例如:

abstract class Human{
    age: string;
    constructor(age: string){
        this.age = age;
    }
    abstract name(): void
}

class Human1 extends Human{
    constructor(age: string){
        super(age);
        this.name()
        
    }
name(): void {
    Human.prototype.name.call(this); // this is allowed despite that name is undefined/abstract
    let a = "do something";
    }
}

let a = new Human1("23")

有没有办法让 Typescript 在这里抛出错误?

javascript typescript abstract-class typescript-typings
© www.soinside.com 2019 - 2024. All rights reserved.