Closed
Description
TypeScript Version: 2.6.2
Search Terms:
Generic, parameter, constraint
Code
//Given abstract generic class
interface IA {
id: string;
}
abstract class A<TA extends IA> {
abstract save(): TA
}
//Given that's class concerete implementation
interface IB extends IA {
name: string;
}
class B extends A<IB>
{
save(): IB {
return null as any as IB;
}
}
//How to enforce the "matching" types?
class C {
callSave<TClass extends A<TInterface>,
TInterface extends IA>(): TInterface {
return null as any as TInterface;
}
}
var c = new C();
//In C# that would fail
c.callSave<B, IA>();
Expected behavior:
Code does not compile
Actual behavior:
Code compiles