我有一个带有抽象方法的抽象类。我发现如果我用
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 在这里抛出错误?