Common causes
- Storing the result of a void-returning function: const result = array.forEach(...)
- Passing a void-returning callback where a value-returning callback is expected
- Chaining methods on a void result: arr.forEach() returns void, not the array
- A function was changed to return void but its return value is still being used
How to fix it
- Don't capture the return value of void functions — just call without assignment
- Use a value-returning method instead: map() returns values, forEach() does not
- Restructure the code to not depend on the return value of the void function
- If the function should return a value, update its implementation and return type
Example
const result: string[] = ['a', 'b'].forEach(x => x.toUpperCase());
// error TS2322: Type 'void' is not assignable to type 'string[]'.Assigning the result of forEach, which returns void, to a typed string[] variable
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.
