TypeScript 7 reference · Utility Types

TypeScript Parameters<Type> Utility Type

Get a function's parameter types as a tuple, useful for wrappers that pass arguments through.

TypeScript 7 Since 3.1

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

Syntax

Parameters<Type>

Parameters

ParameterDescription
Type A function type.

Return value

A tuple type.

Examples

A tuple of the parametersTry it yourself
function sendEmail(to: string, subject: string, urgent: boolean) {
  return `${urgent ? "URGENT " : ""}${subject} -> ${to}`;
}
type EmailArgs = Parameters<typeof sendEmail>; // [string, string, boolean]
const args: EmailArgs = ["[email protected]", "Hi", false];
console.log(sendEmail(...args));

Output

Hi -> [email protected]
Typed wrappersTry it yourself
function logged<F extends (...a: any[]) => any>(fn: F) {
  return (...args: Parameters<F>): ReturnType<F> => {
    console.log("calling with", args);
    return fn(...args);
  };
}
const add = logged((a: number, b: number) => a + b);
console.log(add(2, 3));

Output

calling with [ 2, 3 ]
5

Version history

VersionChange
TypeScript 3.1Added

Was this page helpful?