Skip to content

assert

Asserts that a condition is true. Throws if it is not.

Use in place of /* v8 ignore *\/ for defensive guards that should never trigger at runtime but would otherwise create uncovered branches.

Import:

import { assert } from '@mnaoumov/typescript-lib/type-guards';

Signature:

function assert(isTrue: boolean, errorOrMessage: string | Error): void

Parameters:

Parameter Type Description
isTrue boolean The condition to assert.
errorOrMessage string | Error The error or message to throw if the condition is false.

Returns: void