Parameters<typeof addToCart> is the tuple [sku: string, quantity: number, options?: { giftWrap?: boolean }]. A wrapper that logs, retries or times a call can take ...args with that type and pass them on, and every call to the wrapper is checked as if it were a call to addToCart (TS2345 for a string quantity, as the example shows).
Indexing the tuple names one parameter's type: Parameters<typeof addToCart>[2] is the options object. The handbook gives TypeScript 3.1 as the release that added Parameters.
At a glance
| Use | JSDoc in a .js file | TypeScript in a .ts file |
|---|---|---|
| All parameters, as a tuple | /** @param {Parameters<typeof addToCart>} args */
function f(...args) {} | function f(...args: Parameters<typeof addToCart>) {} |
| One parameter | /** @typedef {Parameters<typeof addToCart>[2]} AddOptions */ | type AddOptions = Parameters<typeof addToCart>[2]; |
Examples
/**
* @param {string} sku
* @param {number} quantity
* @param {{ giftWrap?: boolean }} [options]
*/
export function addToCart(sku, quantity, options) {
return { sku, quantity, giftWrap: options?.giftWrap ?? false };
}
/** @param {Parameters<typeof addToCart>} args */
export function addAndLog(...args) {
console.info("add to cart", ...args);
return addToCart(...args);
}
/** @typedef {Parameters<typeof addToCart>[2]} AddOptions */
/** @type {AddOptions} */
const gift = { giftWrap: true };
addAndLog("TEE-01", 2, gift);
addAndLog("TEE-01", "2");error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.export function addToCart(sku: string, quantity: number, options?: { giftWrap?: boolean }) {
return { sku, quantity, giftWrap: options?.giftWrap ?? false };
}
export function addAndLog(...args: Parameters<typeof addToCart>) {
console.info("add to cart", ...args);
return addToCart(...args);
}
type AddOptions = Parameters<typeof addToCart>[2];
const gift: AddOptions = { giftWrap: true };
addAndLog("TEE-01", 2, gift);
addAndLog("TEE-01", "2");error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} The @param on a rest parameter
For function addAndLog(...args), the tag is @param {Parameters<typeof addToCart>} args, the whole tuple, without the three dots. With a tuple type, TypeScript knows the length and the type of each position, optional ones included.
Gotchas
- For a function from a library,
Parameters<typeof libraryFunction>follows the library's own types and stays right when it upgrades. ConstructorParameters<typeof SomeClass>is the counterpart for a class's constructor.
Questions
How do I type a wrapper function's arguments in JSDoc?
Give the rest parameter the wrapped function's parameter tuple: @param {Parameters<typeof original>} args on function wrapper(...args).
Sources
- Utility Types: Parameters<Type> · TypeScript handbook
Last reviewed 20 October 2026.