Common causes
- Spreading a general array (string[], number[]) into a function that expects specific individual arguments
- Dynamically building an argument list as an array and spreading it into a typed function
- The spread value is typed as an array and the function has a specific, fixed signature
- Using apply() alternatives with spread where the argument types can't be verified
How to fix it
- Type the array as a tuple: const args: [string, number] = ['hello', 42]; fn(...args)
- Use as const to make the array a tuple: const args = ['hello', 42] as const
- Change the function to accept rest parameters: function fn(...args: [string, number])
- Pass arguments individually rather than spreading if the list is short
Example
function add(a: number, b: number): number { return a + b; }
const args = [1, 2];
add(...args);
// error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter.Spreading a number[] array into a function — TypeScript can't verify the element count or types match
Browse more errors
The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.
