I'm having trouble inferring the return type of class generic property.
I have this simple setup that works:
class A<T extends B> {
constructor(public b: T) {}
getB() {
return this.b
}
bMethodResult() {
return this.b.methodOne()
}
}
class B {
methodOne() {
return { status: 'ok' }
}
}
const aOne = new A(new B())
aOne.getB() // :B
aOne.bMethodResult() // {status:string}
As you can see TS correctly infers the return type of aOne.bMethodResult().
However, if I try to pass in a child of the B class with a different method signature, TS is not updating the return type to be the B child class method.
class BChild extends B {
methodOne() {
return { status: 'ok', data: true }
}
}
const aTwo = new A(new BChild())
aTwo.getB() // : BChild // ok
aTwo.bMethodResult() // : {status:string }
// I want it to be {status:string, data:boolean}
Is there a way I could get the return type of the child class?