assertExists

import { assertExists } from "jsr:@ende/assert";

function

function assertExists<T>(actual: T, msg?: string): asserts actual is NonNullable<T>

Make an assertion that actual is not null or undefined. If not then throw.

actual: T

The actual value to check.

msg?: string

The optional message to include in the error if the assertion fails.

Example: Usage

import { assertExists } from "@ende/assert";

assertExists("something"); // Doesn't throw
assertExists(undefined); // Throws

Source