Error class that produces a compile-time error if cases for a value weren’t covered exhaustively (e.g. via switch).

enum Color { Red, Green }
function colorToString(color: Color) {
switch (color) {
case Color.Red:
return 'RED';
default:
// @ts-expect-error: Argument of type 'Color.Green' is not
// assignable to parameter of type 'never'.
throw new UnexpectedValueError(color);
}
}

Hierarchy

  • Error
    • UnexpectedValueError

Constructors

Properties

cause?: unknown
message: string
name: string
stack?: string
prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any

Optional override for formatting stack traces

stackTraceLimit: number

Methods

  • Create .stack property on a target object

    Parameters

    • targetObject: object
    • OptionalconstructorOpt: Function

    Returns void