Complete the code to declare a generic factory function that returns an instance of type T.
function createInstance<T>(ctor: { new(): [1] }): T {
return new ctor();
}The generic type T is used to specify the return type of the factory function. The constructor signature must return T to create an instance of that type.
Complete the code to define a generic factory interface with a create method.
interface Factory<T> {
create(): [1];
}void as the return type which means no value is returned.any which loses type safety.The create method should return an instance of the generic type T.
Fix the error in the generic factory function signature to correctly accept a constructor.
function factory<T>([1]: { new(): T }): T { return new ctor(); }
The parameter name ctor is used to represent the constructor function. It must match the name used inside the function body.
Fill both blanks to create a generic factory function that accepts a constructor and returns an instance.
function create[1]<T>([2]: { new(): T }): T { return new ctor(); }
The function name createFactory describes the factory pattern. The parameter ctor is the constructor used to create the instance.
Fill all three blanks to implement a generic factory class with a create method.
class Generic[1]<T> { constructor(private [2]: { new(): T }) {} create(): [3] { return new this.ctor(); } }
T consistently.The class is named GenericFactory. The constructor parameter ctor is the constructor function. The create method returns an instance of type T.