/** * The general runtime assertion utilities of `@xmachines/play`. * * @packageDocumentation */ /** * Asserts that `value` is not `null` and not `undefined`, then returns it with the * type `NonNullable`. One expression therefore holds the guard and the narrowed * value. * * A non-null assertion (`value!`) is different: it produces `undefined`, and your * code then fails later with a message such as "undefined is not an object". This * function throws a clear error at the point of the failure. * * An assertion function of the form `asserts value is T` is also different: this * function returns the narrowed value directly. Therefore the call site needs no * second variable and no `as` cast. * * @param value - The value to check. * @param name - The optional name in the error message. It identifies the missing * value, for example the name of the variable or of the injection key. * @returns `value` with the type `NonNullable`, without `null` and without `undefined`. * @throws {NonNullableError} When `value` is `null` or `undefined`. * * @example * ```ts * import { assertNonNullable } from "@xmachines/play"; * * // inject() and assertNonNullable in one line, with no `!` and no second variable: * const actor = assertNonNullable(inject("actor"), "actor"); * * // A lookup of an element: * const el = assertNonNullable(document.getElementById("app"), "#app"); * ``` */ export declare function assertNonNullable(value: V, name?: string): NonNullable; //# sourceMappingURL=utils.d.ts.map