ReviseAlgo Logo

Functions in TypeScript

void vs undefined Return Types

Understand the subtle differences between void and undefined return types in TypeScript, callback return assignability, and avoiding strict return errors.

Last Updated: July 29, 2026 10 min read

While both void and undefined represent empty or missing values in JavaScript, TypeScript enforces distinct type-checking rules for void vs undefined as return types.

1. void Return Type: "Ignore Output"

void as a return type indicates that a function does not return a meaningful value. The function can complete execution without a return statement or return undefined.

2. undefined Return Type: "Must Return Undefined Value"

When a function return type is explicitly annotated as undefined, the function MUST explicitly include a return statement that yields undefined.

3. The Critical Difference in Callback Assignability

The most crucial difference between void and undefined occurs when typing callback functions:

() => void Callbacks (Permissive Return)

A callback function typed with void return type (() => void) allows the callback to return any value, but the caller guarantees it will ignore the returned value.

() => undefined Callbacks (Strict Return)

If forEach callback was typed as () => undefined, the arrow function above would fail compilation because Array.push() returns a number!

4. Interactive Code Playground

Test void vs undefined assignability below:

5. Common Pitfalls & Edge Cases

  • Using undefined When You Mean void: Avoid annotating side-effect functions as (): undefined. Always use (): void for procedures and side-effects.
  • 6. Summary Comparison Table

    Featurevoid Return Typeundefined Return Type
    Requires return Statement?NoYes (return undefined;)
    Primary Use CaseSide-effect procedures & loggingFunctions explicitly yielding undefined
    | Callback Return Assignability | Permissive (Callback can return any value, but it is ignored) | Strict (Callback must return undefined) |