I am trying to wrap my head around this. I have been working with generics in Java and C#, but only recently in TypeScript. So, can someone please explain to me this madness?
constructor FooAdapter(): FooAdapter
Type 'FooAdapter' is not assignable to type 'A'.
'FooAdapter' is assignable to the constraint of type 'A', but 'A' could be instantiated with a different subtype of constraint 'FooAdapter'.
ts(2322)
From the following snippet:
interface IFoo {}
interface IAdapter<F extends IFoo> {
getFoo():F
}
abstract class AbstractFoo<F extends IFoo> {
abstract something<A extends IAdapter<F>>():A;
}
class Foo implements IFoo {}
class FooAdapter implements IAdapter<Foo> {
getFoo() { return new Foo(); }
}
class FooFactory extends AbstractFoo<Foo> {
something<A extends FooAdapter>():A {
return new FooAdapter(); // <--- ts(2322) here
}
}
How to fix this error?