I'm trying to implement a factory in typescript that returns a generic type.
Already figured out that I need to pass the type as the first argument, and setting it's type to a CTOR signature (new () => T in this example).
The problem begins when I want to pass a generic type to the factory - I get an error saying:
Value of type 'typeof G' is not callable. Did you mean to include 'new'?(2348).
Is there any way to achieve this?
Here is a simplified version of the problem:
// Generic class
class G<T>{}
// Standard non generic
class B{}
function make<T>(t: new () => T){
return new t()
}
// Works
make(B)
// Value of type 'typeof G' is not callable. Did you mean to include 'new'?(2348)
make(G<number>)
Typescript playground link to the above code.