assert function

Assert that a condition is true, throwing an error if not.

Example

assert(user !== null, "User not found");
// TypeScript will narrow user to non-null here

Signature

assert(condition: any, message: string): condition is unknown

Parameters

condition

The condition to check

message

Error message if condition is false

Throws

Error if condition is falsy