Course contentsShow
← TypeScript
Lesson 704 of 1,79616. Utility TypesFree lesson

ConstructorParameters: Extract Constructor Args

Apply ConstructorParameters<T> to class types to get a tuple of constructor parameter types.

ConstructorParameters: Extract Constructor Args

You'll learn how to use ConstructorParameters<T> to extract a tuple type representing a class constructor's parameter types.

What Problem Does It Solve?

Sometimes you need to reference the exact parameter types that a class constructor accepts—without manually rewriting them. Maybe you're building a factory function that creates instances, or you need to validate constructor arguments before instantiation. ConstructorParameters<T> gives you those types automatically.

The Syntax

class Database {
  constructor(host: string, port: number, ssl: boolean) {
    // implementation
  }
}

type DbConstructorArgs = ConstructorParameters<typeof Database>;
// Result: [host: string, port: number, ssl: boolean]

Notice you pass typeof Database, not Database itself. ConstructorParameters needs the constructor function type, not the instance type.

How It Works

The utility extracts parameter types as a tuple, preserving order and names (if labeled). You can use this tuple type in factory functions, configuration objects, or anywhere you need to mirror constructor signatures:

function createDatabase(...args: ConstructorParameters<typeof Database>) {
  return new Database(...args);
}

createDatabase("localhost", 5432, true); // ✓ Valid
createDatabase("localhost"); // ✗ Error: Missing arguments

With Generic Classes

It works with generic classes too. The extracted tuple reflects the type parameters:

class Container<T> {
  constructor(value: T) {}
}

type ContainerArgs = ConstructorParameters<typeof Container<string>>;
// Result: [value: string]

Key Takeaway: Use ConstructorParameters<typeof ClassName> to extract constructor parameter types as a tuple, enabling type-safe factory functions and dynamic instantiation patterns without duplicating type definitions.