igcv3 - v1.1.0
    Preparing search index...

    Function assertNever

    • Exhaustiveness check for discriminated unions. Use in the default case of switch statements to ensure all cases are handled. TypeScript will report a compile-time error if a case is missing.

      Parameters

      • value: never

        The value that should be of type never if all cases are handled

      • Optionalmessage: string

        Optional custom error message

      Returns never

      Never returns - always throws

      Always throws with the unhandled value

      type Shape = { kind: 'circle'; radius: number } | { kind: 'square'; size: number };

      function area(shape: Shape): number {
      switch (shape.kind) {
      case 'circle': return Math.PI * shape.radius ** 2;
      case 'square': return shape.size ** 2;
      default: return assertNever(shape.kind);
      }
      }