conditional
InstanceType<T>
Given a constructor type T (typically obtained via `typeof ClassName`), returns the type of an instance produced by `new T()`. Useful for factory functions and generic wrappers over classes.
type InstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any Usage patterns
| Pattern | Purpose |
|---|---|
| InstanceType<typeof Cls> | Get the instance type from a class constructor |
| ConstructorParameters<typeof Cls> | Companion for the constructor's argument tuple |
| abstract new (...args: any) | Supported signature form (TS 4.2+) |
| InstanceType<T> & { extra: X } | Intersect an instance with extra runtime-added props |
Examples
class Foo { hello() { return 'hi'; } }
type F = InstanceType<typeof Foo>; Result: Foo
function make<T extends new (...a: any) => any>(C: T): InstanceType<T> {
return new C();
} Generic factory returning the correct instance type
type ErrInstance = InstanceType<ErrorConstructor>; Result: Error — reuses built-in constructor
type Bad = InstanceType<() => void>; // Error T must have a construct signature — plain functions error out
Gotcha
Takes the CONSTRUCTOR type, not the class body itself — always pair with `typeof`. If a class has multiple construct signatures (rare), only the last is used.
Related utility types
ConstructorParameters<T>
Extracts the parameter tuple of a class constructor T. Mirrors Parameters but operates on `new (...)` signatures instead of call signatures.
ReturnType<T>
Infers the return type of a function type T using `infer R`. Widely used to derive types from existing functions without redeclaring them.
ThisType<T>
A marker interface with no members that, when used in a contextual type, sets the `this` type inside method-like properties of an object literal. Requires `noImplicitThis` to be genuinely useful and is a compile-time only hint.
infer R
A keyword usable only inside the extends clause of a conditional type that introduces a fresh type variable inferred from the matched shape. It is the primitive that powers ReturnType, Parameters, InstanceType, Awaited, and countless custom utilities.
Awaited<T>
Models the type produced by awaiting T, recursively unwrapping nested Promises (and other thenables). Introduced in TS 4.5 and used internally by the `await` expression's type.
← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never