@tremendous/help
    Preparing search index...

    Function unreachable

    • Throws a TypeScript error if an unreachable case is reached. Often used to ensure that a switch statement is exhaustive.

      Parameters

      • x: never

        The value that should never be reached

      Returns never

      • Throws an error
      type PossibleValues = 'a' | 'b';

      const handleValue = (value: PossibleValues) => {
      switch (value) {
      case 'a':
      return 'A';
      case 'b':
      return 'B';
      default:
      return unreachable(value);
      }
      }

      If 'c' is added to PossibleValues but not handled in the switch statement,
      TypeScript will throw an error.