This TypeError is thrown when the spread operator (...) is used on a value that does not implement the iterable protocol. Arrays, strings, Sets, and Maps are iterable; plain objects, null, undefined, and numbers are not.
Why it happens
- •Spreading null or undefined into an array literal.
- •Spreading a plain object ({}) in an array context (only works in object spread).
- •Spreading a value from an API that returned null instead of an array.
- •Attempting to spread a number or boolean value.
Examples
Code that triggers the error
const a = [1, 2];
const b = null;
const merged = [...a, ...b];Error output
TypeError: b is not iterable
How to fix it
Guard the value before spreading with a fallback: [...(value ?? [])]. Verify that API responses that should be arrays are actually arrays. Use Array.isArray() to validate before spreading. Remember: object spread ({...obj}) and array spread ([...arr]) have different requirements.
Fixed code
const a = [1, 2];
const b = null;
const merged = [...a, ...(b ?? [])];
console.log(merged); // [1, 2]Related errors
Ready to practice your English at work?
Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.
Try Lingua-e for free