0Pricing
TypeScript Academy · Lesson

void, never, and Function Signatures

Understand void for no-return and never for unreachable code.

void, never, and Function Signatures is a free TypeScript Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Welcome

Two special return types — void and never — represent functions that don't produce a useful value and functions that never complete normally.

void: No Meaningful Return

void is used when a function performs a side effect but doesn't return a value. It allows returning undefined but signals that the return value should not be used.
function logError(msg: string): void {
  console.error(msg);
  // implicit return undefined
}

Difference Between void and undefined

void and undefined are similar but different. A void-typed function can return undefined. But void signals the caller should ignore the return value.
const fn: () => void = () => 42; // Allowed! Caller ignores return
const fn2: () => undefined = () => 42; // Error

void in Callbacks

When typing a callback parameter, void indicates the caller does not use the return value. This allows callbacks to return any type.
function run(cb: () => void): void { cb(); }
run(() => 'hello'); // OK — return value ignored

never: The Unreachable Type

never represents a value that never occurs. A function returning never either throws or loops infinitely.
function fail(msg: string): never {
  throw new Error(msg);
}
function loop(): never {
  while (true) {}
}

never in Exhaustiveness Checks

never is used in switch statements to ensure all union cases are handled. Assigning to never causes an error if a case is missed.
type Shape = 'circle' | 'square';
function area(s: Shape): number {
  switch (s) {
    case 'circle': return 3.14;
    case 'square': return 1;
    default:
      const _: never = s; // Error if a new shape is added
      return 0;
  }
}

never Is a Subtype of Everything

never is assignable to every type (it never happens, so it vacuously satisfies any type). No other type is assignable to never.

Function Type Signatures

A function type is written as `(param: Type) => ReturnType`. This describes functions as first-class values.
type Handler = (event: MouseEvent) => void;
type Transform = (input: string) => string;

Call Signatures in Interfaces

Interfaces can define callable types using a call signature syntax.
interface Formatter {
  (value: string): string;
  locale: string;
}

Construct Signatures

Interfaces can also define constructable types using the new keyword in a construct signature.
interface Constructor {
  new (name: string): Animal;
}

Combining void and never in Error Handling

Functions that always throw use never. Functions that swallow errors and return nothing use void. This distinction matters for control flow analysis.
function orThrow(val: string | null): string {
  if (val === null) fail('null!'); // never
  return val; // TypeScript knows this is reachable
}

Quick Check

Which return type signals that a function will always throw an error and never return normally?

Recap

Use void for side-effect functions with no meaningful return. Use never for functions that throw or loop. never enables exhaustiveness checking and is a subtype of all types.

Frequently asked questions

Is the “void, never, and Function Signatures” lesson free?

Yes — the full text of “void, never, and Function Signatures” is free to read here on the web, and the TypeScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “void, never, and Function Signatures”?

Understand void for no-return and never for unreachable code. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start TypeScript Academy?

No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “void, never, and Function Signatures” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this TypeScript Academy lesson?

Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Parameter and Return Type Annotations
  2. Optional and Default Parameters
  3. Rest Parameters and Spread with Types
  4. void, never, and Function Signatures
← Back to TypeScript Academy