Declare class type with TypeScript (pass class as parameter)
As you mentioned, what you are looking to is how to describe class constructor and not the instance. It can be achieved by:
const foo = function(ctor: new() => SomeSuperClass) {
...
}
Or alternatively (same result in this case):
const foo = function(ctor: typeof SomeSuperClass) {
...
}
This also requires A
and B
to have parameterless constructors
After looking at this answer, it looks like the only way to do this is like so:
interface ISomeSuperClass {
new (): SomeSuperClass;
}
where foo would then become:
const foo = function(Clazz: ISomeSuperClass){
const v = new Clazz();
}
This seems kind of weird, but it compiles.