Typed argument forwarding
Derive the argument tuple for a wrapper or forwarding function.
TypeScript · Type Alias
Parameters<Type> creates a tuple containing the parameter types of a function type. It is useful for reusing or transforming a function's argument list without manually duplicating it.
Parameters<Type> evaluates a function type's parameter list as a tuple. Applying it to a function declaration via typeof preserves the parameter names and optionality represented by that function type; for overloaded functions, TypeScript uses the last signature.
Parameters<Type>| Name | Type | Description |
|---|---|---|
Type | function type | A function type whose parameter types should be extracted. |
A tuple containing the parameter types of Type.
function greet(name: string, age?: number): string {
return age === undefined ? `Hello, ${name}` : `Hello, ${name}, age ${age}`;
}
type GreetParameters = Parameters<typeof greet>;
const args: GreetParameters = ["Ada", 36];
greet(...args);The tuple type captures the parameter list of greet, including its optional second parameter.
Derive the argument tuple for a wrapper or forwarding function.
Keep mock, spy, or adapter arguments synchronized with an existing function.
Build APIs that transform a function while preserving its parameter list.
ReturnTypeConstructorParametersInstanceTypeInferring Within Conditional Types