UNPKG

typedash

Version:

modern, type-safe collection of utility functions

33 lines 1.08 kB
//#region src/functions/assert/assert.d.ts /** * Asserts that a condition is true, throwing an Error if it is not. * @param condition A condition that should be true * @param message A message to use in the Error that will be thrown if the condition is falsy * @throws An `AssertionError` if the condition is falsy * @example * ```ts * function doWork(value: number | undefined) { * assert(value !== undefined, 'value should be defined'); * // value is now narrowed to number * * return value + 1; * } * ``` * @example * ```ts * assert(1 === 1); // OK * assert(1 === 2); // throws AssertionError * assert(1 === 2, '1 should equal 2'); // throws AssertionError: 1 should equal 2 * ``` */ declare function assert(condition?: unknown, message?: string): asserts condition; /** * An error that is thrown when an assertion is not satisfied. * Thrown by {@link assert}. */ declare class AssertionError extends Error { constructor(message?: string); } //#endregion export { assert as n, AssertionError as t }; //# sourceMappingURL=assert-dAm_7rI2.d.cts.map