UNPKG

1.09 kBTypeScriptView Raw
1type MessageFn = () => string;
2/**
3 * @name assert
4 * @summary Checks for a valid test, if not Error is thrown.
5 * @description
6 * Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an Error with the supplied `message`. When `test` passes, `true` is returned.
7 * @example
8 * <BR>
9 *
10 * ```javascript
11 * const { assert } from '@polkadot/util';
12 *
13 * assert(true, 'True should be true'); // passes
14 * assert(false, 'False should not be true'); // Error thrown
15 * assert(false, () => 'message'); // Error with 'message'
16 * ```
17 */
18export declare function assert(condition: unknown, message: string | MessageFn): asserts condition;
19/**
20 * @name assertReturn
21 * @description Returns when the value is not undefined/null, otherwise throws assertion error
22 */
23export declare function assertReturn<T>(value: T | undefined | null, message: string | MessageFn): T;
24/**
25 * @name assertUnreachable
26 * @description An assertion helper that ensures all codepaths are followed
27 */
28export declare function assertUnreachable(x: never): never;
29export {};