TypeScript 7 reference · Utility Types

TypeScript InstanceType<Type> Utility Type

Get the type of the object a class constructor creates, from the constructor's type.

TypeScript 7 Since 2.8

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

InstanceType<Type>

Parameters

ParameterDescription
Type A constructor type (typeof SomeClass).

Return value

The instance type.

Examples

From typeof ClassTry it yourself
class Logger {
  constructor(public prefix: string) {}
  log(msg: string) {
    console.log(`${this.prefix} ${msg}`);
  }
}
type LoggerInstance = InstanceType<typeof Logger>;
const l: LoggerInstance = new Logger("[app]");
l.log("started");

Output

[app] started
A typed factoryTry it yourself
function make<C extends new (...args: any[]) => any>(Cls: C, ...args: ConstructorParameters<C>): InstanceType<C> {
  return new Cls(...args);
}
class Point {
  constructor(public x: number, public y: number) {}
}
const p = make(Point, 3, 4);
console.log(p.x + p.y, p instanceof Point);

Output

7 true

Version history

VersionChange
TypeScript 2.8Added

Was this page helpful?