function-types
ConstructorParameters<T>
Extracts the parameter tuple of a class constructor T. Mirrors Parameters but operates on `new (...)` signatures instead of call signatures.
type ConstructorParameters<T extends abstract new (...args: any) => any> = T extends abstract new (...args: infer P) => any ? P : never Usage patterns
| Pattern | Purpose |
|---|---|
| ConstructorParameters<typeof Cls> | Reuse a class's constructor arguments |
| abstract new (...args) | The signature form it destructures |
| InstanceType<typeof Cls> | Companion for extracting the instance type |
| ...args: ConstructorParameters<T> | Spread into a factory or wrapper |
Examples
class Point { constructor(public x: number, public y: number) {} }
type PArgs = ConstructorParameters<typeof Point>; Result: [x: number, y: number]
function factory<T extends new (...a: any) => any>(Cls: T, ...args: ConstructorParameters<T>) {
return new Cls(...args);
} Type-safe generic factory function
type EArgs = ConstructorParameters<ErrorConstructor>; With modern lib (ES2022+), Error's second overload adds `options`, so `EArgs = [message?: string, options?: ErrorOptions]`. Last overload wins.
type Bad = ConstructorParameters<() => void>; // Error T must have a construct signature — plain functions error out
Gotcha
Applies to `typeof ClassName` (the constructor), not the instance type. Abstract classes are supported since TS 4.2 thanks to the `abstract new` signature.
Related utility types
Parameters<T>
Extracts the parameters of a function type T as a tuple. Enables reusing a function's argument list for wrappers, currying, or higher-order utilities.
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.
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.
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.
ThisParameterType<T>
Extracts the explicit `this` parameter type from a function T, or `unknown` if none is declared. Useful for reflecting on method-style callbacks that require a specific caller.
← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never