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
Syntax
Parameters<Type>
Parameters
| Parameter | Description |
|---|---|
Type |
A function type. |
Return value
A tuple type.
Examples
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]
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
| Version | Change |
|---|---|
| TypeScript 3.1 | Added |
Related
ReturnType<Type>· Get the return type of a function type, so other code can reuse it without repeating it.- TypeScript Utility Types · tutorial