For a rest parameter, function tagProduct(sku, ...tags), the @param type is the type of one argument with three dots in front: @param {...string} tags. Inside the function, tags is string[], and every extra argument at a call is checked against string (TS2345 for a number, as the second example shows).
Inside a function type the TypeScript form applies: {(...tags: string[]) => void}, with the array type after the colon.
At a glance
| Use | JSDoc in a .js file | TypeScript in a .ts file |
|---|---|---|
| A rest parameter | /** @param {...string} tags */
function f(...tags) {} | function f(...tags: string[]) {} |
| In a function type | {(...tags: string[]) => void} | (...tags: string[]) => void |
Examples
/**
* @param {string} sku
* @param {...string} tags
* @returns {{ sku: string, tags: string[] }}
*/
export function tagProduct(sku, ...tags) {
return { sku, tags };
}
tagProduct("TEE-01");
tagProduct("TEE-01", "cotton", "summer", "sale");export function tagProduct(sku: string, ...tags: string[]): { sku: string; tags: string[] } {
return { sku, tags };
}
tagProduct("TEE-01");
tagProduct("TEE-01", "cotton", "summer", "sale");jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} /**
* @param {string} sku
* @param {...string} tags
*/
export function tagProduct(sku, ...tags) {
return { sku, tags };
}
tagProduct("TEE-01", "cotton", 2024);error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} // No rest parameter: TypeScript sees the use of `arguments` and lets callers pass any number of values.
export function sum() {
let total = 0;
for (const value of arguments) total += value;
return total;
}
sum(19.5, 12, 4.95);jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} Functions that read arguments
Older code reads extra values from arguments instead of declaring a rest parameter. TypeScript notices the use of arguments in a .js file and lets callers pass any number of values, as the third example shows; the values themselves are not typed. Converting to a rest parameter with a @param {...T} type gives the same freedom with checking.
Under TypeScript 6.0 and 7.0
Every example on this page also runs under TypeScript 6.0.3 and 7.0.2 when this site is built. One of them reports something different from 5.9.3, the version the page describes; the ✗ on its badge links to its entry below.
Using arguments no longer allows extra arguments
The pattern: A function with no parameters that reads arguments, called with values.
Why: 5.9 gave such a function an implicit ...args: any[]. The port's list of changes says using arguments no longer implies that parameter, so a call with values is TS2554. Source: CHANGES.md: arguments usage within a JS function body no longer implies a rest parameter.
A function that reads arguments accepts any number of them sum.js
- TypeScript 5.9.3
No errors.
- TypeScript 6.0.3same as 5.9.3
No errors.
- TypeScript 7.0.2differs from 5.9.3
sum.js(8,5): error TS2554: Expected 0 arguments, but got 3.
What works in every version: Declare a rest parameter: function sum(...values) with @param {...number} values.
The example Rest parameters with {...T} on this page shows it, with the same result under every version.
Gotchas
- Write the element type in
@param, not the array type:{...string}, not{...string[]}. - TypeScript 7.0 no longer lets callers pass extra values to a function just because it reads
arguments(the section Under TypeScript 6.0 and 7.0 has what 7.0.2 reports); declare a rest parameter instead.
Questions
How do I document a variadic function in JSDoc?
Declare a rest parameter and type one element of it: @param {...number} values for function sum(...values).
Sources
- JSDoc Reference: @param · TypeScript handbook
- More on Functions: rest parameters and arguments · TypeScript handbook
- Type Checking JavaScript Files: var-args parameters · TypeScript handbook
Last reviewed 21 October 2026.