0Pricing
TypeScript Academy · Lesson

The void Type in Functions

How void differs from undefined in function return positions.

The void Return Type

void describes a function that returns no useful value. The function still completes; it just doesn't produce something you should use. It's the type of functions called for their side effects.

function log(message: string): void {
  console.log(message);
}
log('Hello void');

Inferred void

If a function has no return statement (or only bare return;), TypeScript infers void automatically. You rarely need to write it explicitly, though it documents intent.

function greet(name: string) {
  console.log('Hi ' + name);
  // no return -> inferred void
}
greet('Ada');

All lessons in this course

  1. Understanding unknown vs any
  2. The never Type and Impossible States
  3. The void Type in Functions
  4. Type-Safe Handling of unknown
← Back to TypeScript Academy