Course contentsShow
← TypeScript
Lesson 134 of 1,7963. Basic TypesFree lesson

Introduction to never: The Bottom Type

Understand never as the type of values that never occur, representing impossibility.

Introduction to never: The Bottom Type

What you'll learn: You'll discover the never type, which represents values that can never exist—TypeScript's way of expressing impossibility.

What Is never?

The never type is TypeScript's bottom type—it represents values that never occur. While this sounds abstract, think of it as TypeScript's way of saying "this code path is impossible" or "this function will never successfully return."

Unlike void (which means "returns nothing useful"), never means "doesn't return at all" or "can't possibly have a value."

When Does never Appear?

TypeScript uses never in situations where a value cannot exist:

Functions that never return:

function throwError(message: string): never {
  throw new Error(message);
  // Execution stops—nothing is returned
}

function infiniteLoop(): never {
  while (true) {
    // This never exits
  }
}

Impossible type narrowing:

function handleValue(value: string | number) {
  if (typeof value === "string") {
    // value is string
  } else if (typeof value === "number") {
    // value is number
  } else {
    // value has type never here—we've eliminated all possibilities!
    const impossible: never = value;
  }
}

Why Does This Matter?

never helps TypeScript prove exhaustiveness. If you handle all possible cases of a union type, what's left over is never—proving you covered everything.

The Analogy

Think of never as a mathematical empty set (∅). Just as no element can belong to the empty set, no value can have type never. It's the absence of possibility.

Key Takeaway: never represents impossibility—code paths that cannot execute or values that cannot exist, helping TypeScript verify you've handled every possible case.