@jiminp/tooltool
    Preparing search index...

    Function unreachable

    • Asserts that a code path is unreachable; throws if executed.

      Use for exhaustiveness checking in switch statements. TypeScript will error if all cases aren't handled.

      Parameters

      • value: never

        Should be never if all cases are handled.

      Returns never

      Always throws with the unexpected value.

      type Fruit = 'apple' | 'banana';

      function getColor(fruit: Fruit): string {
      switch (fruit) {
      case 'apple': return 'red';
      case 'banana': return 'yellow';
      }
      return unreachable(fruit); // Compile error if case missing
      }