是否可以通过某种方式为班级设置隐式自定义返回类型? 例如:
class A { }
class B {
constructor() {
const a = new A();
return a;
}
}
const a = new B(); // here I need `a` to be type of A in typescript, but it is B
console.log(a instanceof A); // => true
我尝试过:
class B {
constructor() {
const a = new A();
return a as A;
// return a as any as A;
}
}