- Explanation of inheritance hierarchy:
class A {}
- Classes B and C extend class A.
class B extends A {}
class C extends A {}
- Using a function to create instances.
namespace D {
function NewInstance<T extends A = A>(iclass: T): T;
}
Desired functionality: removing <T extends A>
should automatically determine the return type based on the input class.
D.NewInstance(B) => B
, D.NewInstance(C) => C
Current behavior: Not setting the generic results in D.NewInstance(B) => A
, D.NewInstance(C) => A