moderator-toolbox-nxg-for-reddit / util/data/assertNever

util/data/assertNever

Functions

assertNever()

assertNever(value, label?): never

Defined in: extension/data/util/data/assertNever.ts:12

Asserts that a code path is unreachable. Used in the default branch of a switch over a discriminated union: if every variant is handled, value narrows to never and this compiles; if a new variant is added without a matching case, value is no longer never and the call becomes a compile error, forcing the new case to be handled. Also throws at runtime as a defensive backstop for malformed data.

Parameters

value

never

The value that should have been narrowed away by prior cases.

label?

string = 'value'

Optional context for the runtime error message.

Returns

never