Parameters Utility Type in TypeScript
Parameters<T> extracts the parameter types of a function as a tuple. Use it to reuse parameter types without duplicating them.
The TypeScript Parameters utility type extracts the parameter types from a function type as a tuple. If a function takes a string, a number, and a boolean, Parameters gives you [string, number, boolean]. It is the inverse of ReturnType: where ReturnType captures what a function produces, Parameters captures what it consumes.
The most practical use is building wrapper functions. You want a wrapper to accept exactly the same arguments as the original function, without duplicating the parameter types by hand.
function saveToDatabase(entity: string, data: Record<string, unknown>) {
console.log(`Saving ${entity}:`, data);
}
type SaveParams = Parameters<typeof saveToDatabase>;SaveParams resolves to [entity: string, data: Record<string, unknown>]. It is a tuple with named elements, so autocomplete shows the parameter names when you use the type elsewhere.
How Parameters works
Parameters takes a function type and produces a tuple of its parameter types. The tuple preserves both the types and the labels of the original parameters.
function connect(host: string, port: number, useTls: boolean): void {
// implementation
}
type ConnectArgs = Parameters<typeof connect>;ConnectArgs resolves to [host: string, port: number, useTls: boolean]. The labels host, port, and useTls are preserved, which improves autocomplete when the tuple is used later.
For a function with no parameters, Parameters returns an empty tuple. For a function with rest parameters, the rest element appears as an array type at the end of the tuple.
Building wrapper functions with Parameters
The strongest use case is writing wrappers that preserve the original function's parameter types. Instead of manually restating the types, use Parameters and the spread operator.
function logToServer(level: string, message: string, metadata?: object) {
// sends log to remote server
}
function safeLog(...args: Parameters<typeof logToServer>) {
try {
logToServer(...args);
} catch {
console.error("Logging failed, but the application continues.");
}
}safeLog accepts exactly the same arguments as logToServer. If logToServer gains a new parameter, safeLog picks it up automatically. The compiler enforces that the call to logToServer inside the wrapper passes the arguments correctly.
This pattern is common in decorators, middleware, and any code that intercepts or augments function calls.
Parameters for dependency injection
Another common pattern is separating a function's dependencies from its call. Parameters lets you extract the argument types and use them elsewhere.
function renderPage(user: { name: string; role: string }, theme: "light" | "dark") {
return `Welcome, ${user.name}. Theme: ${theme}`;
}
type RenderArgs = Parameters<typeof renderPage>;
function prepareRenderArgs(): RenderArgs {
const user = { name: "Ada", role: "admin" };
const theme = "dark" as const;
return [user, theme];
}
renderPage(...prepareRenderArgs());prepareRenderArgs returns a tuple that matches renderPage's parameter types exactly. The compiler checks that the returned array has the right length and each element has the right type.
Parameters with higher-order functions
Parameters works well with generics for building reusable function wrappers. A generic wrapper can take any function and return a new function with the same parameters.
function measureTime<F extends (...args: any[]) => any>(
fn: F,
label: string
): (...args: Parameters<F>) => ReturnType<F> {
return (...args: Parameters<F>) => {
const start = performance.now();
const result = fn(...args);
console.log(`${label} took ${performance.now() - start}ms`);
return result;
};
}The wrapper's return type uses both Parameters and ReturnType utility type in TypeScript to produce a function that is identical to the original in type signature. Calling it with a plain add function gives full autocomplete and type checking on the result:
function add(a: number, b: number) { return a + b; }
const timedAdd = measureTime(add, "add");
timedAdd(3, 4);
// console: add took 0.05msParameters vs writing the tuple by hand
For a function with one or two simple parameters, writing [string, number] by hand is fine. Parameters is more valuable when the function has many parameters, complex parameter types, or is likely to change.
| Approach | Good for | Risk |
|---|---|---|
| Write tuple by hand | 1 to 2 simple params | Drifts when the function signature changes |
| Parameters<typeof fn> | 3+ params, complex types | None. Always in sync |
If the function signature changes, such as a parameter being added, removed, or retyped, the handwritten tuple stays stale until someone notices. Parameters updates immediately and the compiler catches mismatches.
Common mistakes
Using Parameters on a value instead of a type. Parameters<saveToDatabase> does not work. Always use Parameters<typeof saveToDatabase> to first get the function's type. This is the same pattern used with ReturnType. For more on typeof, see typeof type operator in TypeScript.
Expecting Parameters to work with overloaded functions predictably. Parameters extracts the parameters of the last overload signature, not the implementation. If your function has multiple overloads with different parameter lists, declare a separate type alias for the signature you need.
Forgetting that Parameters returns a tuple, not individual types. Parameters gives you a tuple like [string, number], not a union of string or number. To get individual parameter types, use indexed access: Parameters<typeof fn>[0] gives the type of the first parameter.
Rune AI
Key Insights
- Parameters<T> extracts a function's parameter types as a tuple.
- Combine it with typeof to capture the parameters of a specific function.
- Use it to build wrapper functions that preserve the original parameter types.
- For functions with no parameters, it returns an empty tuple [].
- Like all utility types, Parameters exists only at compile time.
Frequently Asked Questions
What does Parameters return for a function with no parameters?
Does Parameters work with overloaded functions?
Can I use Parameters to spread arguments into another function?
Conclusion
Parameters is the complement of ReturnType. Where ReturnType extracts what comes out of a function, Parameters extracts what goes in. Together they let you build higher-order functions and wrappers that stay perfectly in sync with their targets.
More in this topic
TypeScript Compiler Explained
The TypeScript compiler (tsc) turns .ts files into .js files while checking types. Learn what it does, how to use it, and how it fits your workflow.
Set Up ESLint for TypeScript
Install and configure ESLint with typescript-eslint to catch bugs and enforce consistent code style in your TypeScript project.
Pick Utility Type in TypeScript
Pick creates a new type by selecting only the properties you name from an existing type. Use it to build focused types for specific views, API responses, or function parameters.