Complete the code to extract constructor parameter types using ConstructorParameters.
type Params = [1]<Date>;The ConstructorParameters utility type extracts the parameter types of a class constructor as a tuple.
Complete the code to define a class and extract its constructor parameter types.
class Person { constructor(public name: string, public age: number) {} } type PersonParams = [1]<typeof Person>;
ConstructorParameters extracts the parameter types of the Person constructor as a tuple [string, number].
Fix the error in the code to correctly extract constructor parameters of a class.
class Car { constructor(make: string, year: number) {} } type CarParams = ConstructorParameters<[1]>;
typeofYou must use typeof Car to refer to the constructor type of the class Car when using ConstructorParameters.
Fill both blanks to create a function that accepts constructor parameters of a class.
function createInstance(cls: [1], ...args: [2]) { return new cls(...args); }
ConstructorParameters for the argsThe first blank requires a constructor type signature. The second blank uses ConstructorParameters to type the rest parameters.
Fill all three blanks to define a generic function that creates instances using constructor parameters.
function makeInstance<T extends [1]>(cls: T, ...args: [2]<T>): InstanceType<T> { return new cls(...args); } type Params<T> = [3]<T>;
Parameters instead of ConstructorParametersT to a constructor signatureThe generic type T extends a constructor signature. The rest arguments use ConstructorParameters of T. The type alias also uses ConstructorParameters.