I am trying to construct a function which takes a class(Clazz
) as an argument and returns an instance of the same class as follows
function myFunction(Clazz) {
...
return new Clazz();
}
Is there any way to infer the type of Clazz
and set it as the return type of this function?
I am aware that I can probably acheive this using generics as follows:
function myFunction<T>(Clazz: new () => T): T {
...
return new Clazz();
}
var instance = myFunction<myClass>(myClass)
But my intention is to get rid of that repitition of myClass
as seen in the above usage