【发布时间】:2016-09-25 03:23:29
【问题描述】:
我正在尝试弄清楚如何让它正常工作:
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 的类型不匹配。
【问题讨论】:
-
你不需要“parent this”,因为 B 也是 A。
标签: class typescript method-chaining