Reputation: 1044
I'm seeking guidance on creating a class declaration in a .d.ts file.
The class has a method that accepts a typeof T and returns an instance of T.
Upvotes: 3
Views: 2023
Reputation: 275799
You need something that is creatable and then its smooth sailing:
interface Creator<T> {
new (): T;
}
function factory<T>( arg: Creator<T> ): T {
return new arg();
}
// Usage:
class Foo {
something = 123;
}
var foo = factory( Foo ); // foo:Foo
Upvotes: 10