InstanceType⟨Ctor⟩ Utility Type in TypeScript

Опубликовано: 04 Июнь 2026
на канале: Learn Language Hub
13
1

What is InstanceType⟨Ctor⟩ in TypeScript

InstanceType⟨Ctor⟩ is a TypeScript utility type that extracts the instance type produced by a constructor.

In simple terms:

It takes a class (or constructor function) type and gives you the type of the object you get when you do new Ctor(...).

Basic idea

Conceptually:

InstanceType⟨Ctor⟩


means:

The type of an object created by new Ctor(...)

Simple example
class User {
id = 0;
name = "";
}

type UserInstance = InstanceType⟨typeof User⟩;
// User


Explanation:

typeof User is the constructor type (the class itself)

InstanceType⟨...⟩ extracts the type of what the constructor creates

Example with constructor parameters (common combo)
class Logger {
constructor(public level: "info" | "error") {}
log(message: string) {}
}

type LoggerInstance = InstanceType⟨typeof Logger⟩;
// Logger

type LoggerArgs = ConstructorParameters⟨typeof Logger⟩;
// ["info" | "error"]


This lets you reuse both:

the instance type

the constructor argument types

Very common use cases
1. Writing generic factory helpers
function make⟨T extends new (...args: any[]) = any⟩(
Ctor: T,
...args: ConstructorParameters⟨T⟩
): InstanceType⟨T⟩ {
return new Ctor(...args);
}


Now make returns the correct instance type for any class passed in.

2. Working with classes in dependency injection

In DI patterns, you often pass around constructors.
InstanceType lets you get the instance type from the constructor type.

3. Avoiding duplicated types

Instead of writing a separate interface for “the thing created by this class”, you can extract it automatically.

How InstanceType works internally (mental model)

Simplified version:

type InstanceType⟨T⟩ =
T extends new (...args: any[]) = infer R ? R : any;


Meaning:

Check if T is a constructor type

Infer (extract) the created instance type

Return that inferred type

This is built using conditional types and infer.

InstanceType vs typeof

These do different jobs:

typeof User → the constructor type (the class value, used with new)

User → the instance type (the object you get after new User())

Example:

class User {}

type A = typeof User;
// new (...args) = User

type B = User;
// instance type

type C = InstanceType⟨typeof User⟩;
// User

Important things to know
1. Ctor must be a constructor type
type X = InstanceType⟨typeof Math⟩;
// Error: Math is not newable


It works only for things you can call with new.

2. Type‑level only

InstanceType:

does not create objects

does not run constructors

only affects TypeScript’s compile-time checking

When to use InstanceType⟨Ctor⟩

Use it when:

You have a constructor type and want the instance type

You’re writing generic factories or DI containers

You want to keep types in sync automatically

Avoid it when:

You already have the instance type directly

A simpler explicit type is clearer

One‑line summary

InstanceType⟨Ctor⟩ extracts the type of the instance created by a constructor type.