I think this is an issue of implementing generics correctly, but I am not sure.
I created a Github gist representing the problem here: https://gist.github.com/ORESoftware/66b72b4b85262d957cb03ad097e4743e
Say I have this superclass:
class A {
foo(): A {
return this;
}
}
and several subclasses, one for example looks like so:
class B extends A {
bar(): B {
return this;
}
}
so if I do
new B().foo().bar()
this will work at runtime, but it doesn't compile with TypeScript. That's because foo() declares the return type to be A, not type B.
How can I return the type that this is, instead of declaring foo() to always return type A?
I tried this:
but I get this error:

