Loading...
Loading...
By continuing to use the platform, you accept the terms of the Privacy Policy and the use of cookies.
👋 Hi! I'm Dastan, author of Hack Frontend. Always open to professional networking => connect with me on LinkedIn.
Parameters is a utility type in TypeScript that allows finding out what parameter types a function has. It turns a function's argument list into a tuple and helps avoid code duplication.
Parameters<T>
T — function type whose parameters you want to extract.function add(a: number, b: number): number {
return a + b;
}
type AddParameters = Parameters<typeof add>;
// AddParameters has type: [number, number]
In this example:
add takes two parameters of type number.Parameters<typeof add> extracts types of these parameters as tuple [number, number].function multiply(a: number, b: number): number {
return a * b;
}
function processOperation(...args: Parameters<typeof multiply>): number {
// Here args has type [number, number]
return multiply(...args);
}
const result = processOperation(2, 3); // Result: 6
processOperation uses ...args with type [number, number] extracted from multiply function.Parameters will automatically update.Parameters will take types from the very first signature, which may not always match expectations.Parameters is a powerful utility type allowing extraction of function parameter types as a tuple. This promotes stricter typing, reduces duplication and improves code maintainability, especially when functions are used in various wrappers and utilities.