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

← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never