【发布时间】:2017-04-09 08:18:35
【问题描述】:
在下面的代码中,Typescript 编译器说属性 'doit' 在类型 '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();
}
编译器对这个等效代码没有任何问题,这再次让我怀疑这里存在编译器错误。
【问题讨论】:
标签: typescript