InstanceType<T>
Constructs the instance type produced by a constructor function type T.
Syntax
InstanceType<Type> Returns
type — The type of the instance created by calling the constructor T with new.
Examples
class Logger {
log(msg: string) {}
}
type L = InstanceType<typeof Logger>;
const l: L = new Logger();
function factory<T extends new () => any>(Ctor: T): InstanceType<T> {
return new Ctor();
}
Notes
Pass a constructor type, usually `typeof SomeClass`. Uses `infer` over a
`new (...args: any) => infer R` pattern. Pair with `ConstructorParameters` to
build generic factory helpers.