3
我试图找出如何得到这个正常工作:打字稿:如何得到一个子类的方法返回父这个
class A {
john(): B {
return this; // <-- ERROR HERE
}
}
class B extends A {
joe(): B {
return this;
}
}
所以我可以做方法链接:
let instance = new B();
instance.john().joe();
当然,TypeScript抱怨this
不符合B的类型。
因为B也是A,所以你不需要“parent this”。 – AlexG