I've been delving into the world of generics with Java and C#, but TypeScript is throwing me for a loop. Can someone shed some light on this confusion?
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)
Troubleshooting from the code snippet below:
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
}
}
Suggestions on resolving this issue?