5
在下面的代码中,Typescript编译器表示属性'doit'在类型'never'上不存在。这可能是一个编译器错误?属性'x'在类型'never'上不存在
class X {
public foo(): void {
if (this instanceof Y) {
} else {
this.doit();
}
}
private doit(): void {
}
}
class Y extends X {
}
我发现了以下解决方法:
const temp = (this instanceof Y);
if (temp) {
} else {
this.doit();
}
编译器不具有该等效代码,这又使我怀疑这里有一个编译器错误的问题。
由于传统原因需要破解,即Y的源代码无法更改。 – user2486738