I have created a class hierarchy to manage inheritance in my code. Here is an example of how it looks:
class A {
clone(): A {
return new A()
}
methodA() {
return this.clone()
}
}
class B extends A {
clone(): B{
return new B()
}
methodB(): B {
return this.clone()
}
}
const a = new B
a.clone().methodA().methodB()
When I call 'methodA' in class B, I expect it to return a cloned object of B. Surprisingly, it turns out that type inference assumes that calling 'methodA' will always return object A, which leads to unexpected behavior in the last line of the code snippet.