/** * @file * * Assertion and narrowing helpers used throughout the mocks. */ /** * An object whose string keys may be read and written freely. */ export type GenericObject = Record; type NullableConstraint = null extends T ? unknown : undefined extends T ? unknown : never; /** * Throws unless a condition holds, narrowing types for the code after it. * * @param condition - The condition that must be `true`. * @param errorOrMessage - The error to throw, or the message of a new `Error`. * @throws The given error, or an `Error` with the given message, when `condition` is `false`. */ export declare function assert(condition: boolean, errorOrMessage: Error | string): asserts condition; /** * Narrows an object to {@link GenericObject} without any runtime check. * * @param _object - The object to narrow. Not inspected. */ export declare function assertGenericObject(_object: object): asserts _object is GenericObject; /** * Throws when a value is `null` or `undefined`, narrowing it to `NonNullable` for the code after it. * * @typeParam T - The value's type, which must admit `null` or `undefined`. * @param value - The value to check. * @param errorOrMessage - The error to throw, or the message of a new `Error`; by default the message says whether * the value was `null` or `undefined`. * @throws The given error, or an `Error`, when `value` is `null` or `undefined`. */ export declare function assertNonNullable>(value: T, errorOrMessage?: Error | string): asserts value is NonNullable; /** * Views an object as a {@link GenericObject} as well as its own type, without any runtime check. * * @typeParam T - The object's type. * @param $object - The object to view. * @returns The same object, typed so arbitrary string keys can be read and written. */ export declare function ensureGenericObject($object: T): GenericObject & T; /** * Returns a value after checking it is neither `null` nor `undefined`, as {@link assertNonNullable} does. * * @typeParam T - The value's type, which must admit `null` or `undefined`. * @param value - The value to check. * @param errorOrMessage - The error to throw, or the message of a new `Error`. * @returns The same value, typed as `NonNullable`. * @throws The given error, or an `Error`, when `value` is `null` or `undefined`. */ export declare function ensureNonNullable>(value: T, errorOrMessage?: Error | string): NonNullable; export {};