/** * Helper functions that have to do with asserting. * * @module */ import type { TranspiledEnum } from "../types/TranspiledEnum.js"; import type { Tuple } from "../types/Tuple.js"; /** Helper function to throw an error if the provided value is not an array. */ export declare function assertArray(value: T, ...[msg]: [T] extends [readonly unknown[]] ? [ "The assertion is useless because the provided value is already an array." ] : [string]): asserts value is T & unknown[]; /** * Helper function to throw an error if the provided value is not an array with every element being * a boolean. */ export declare function assertArrayBoolean(value: T, ...[msg]: [T] extends [readonly boolean[]] ? [ "The assertion is useless because the provided value is already a boolean array." ] : [string]): asserts value is T & boolean[]; /** * Helper function to throw an error if the provided array does not have the specified length. Will * also type narrow the array into a tuple of the specified length. */ export declare function assertArrayLength(value: E[], // eslint-disable-line complete/prefer-readonly-parameter-types length: N, msg: string): asserts value is Tuple; export declare function assertArrayLength(value: readonly E[], length: N, msg: string): asserts value is Readonly>; /** Helper function to throw an error if the provided value is not an array or is an empty array. */ export declare function assertArrayNonEmpty(value: T, ...[msg]: [T] extends [readonly [unknown, ...unknown[]]] ? [ "The assertion is useless because the provided value is already a non-empty array." ] : [string]): asserts value is T & (T extends ReadonlyArray ? [E, ...E[]] : [unknown, ...unknown[]]); /** * Helper function to throw an error if the provided value is not an array with every element being * a number. */ export declare function assertArrayNumber(value: T, ...[msg]: [T] extends [readonly number[]] ? [ "The assertion is useless because the provided value is already a number array." ] : [string]): asserts value is T & number[]; /** * Helper function to throw an error if the provided value is not an array with every element being * an object (i.e., a TypeScript record). */ export declare function assertArrayObject(value: T, ...[msg]: [T] extends [ReadonlyArray>] ? [ "The assertion is useless because the provided value is already an object array." ] : [string]): asserts value is T & Array>; /** * Helper function to throw an error if the provided value is not an array with every element being * a string. */ export declare function assertArrayString(value: T, ...[msg]: [T] extends [readonly string[]] ? [ "The assertion is useless because the provided value is already a string array." ] : [string]): asserts value is T & string[]; /** Helper function to throw an error if the provided value is not a boolean. */ export declare function assertBoolean(value: T, ...[msg]: [T] extends [boolean] ? [ "The assertion is useless because the provided value is already a boolean." ] : [string]): asserts value is T & boolean; /** * Helper function to throw an error if the provided value is equal to `undefined`. * * This is useful to have TypeScript narrow a `T | undefined` value to `T` in a concise way. */ export declare function assertDefined(value: T, ...[msg]: [undefined] extends [T] ? [string] : [ "The assertion is useless because the provided value does not contain undefined." ]): asserts value is Exclude; /** * Helper function to throw an error if the provided value is not contained within an enum. * * @param value The value to check. * @param transpiledEnum The enum to check against. * @param msg The error message to throw if the check fails. * @param set Optional. A set that contains all of the values of an enum. If provided, this function * will check for existence using the set (instead of the enum itself). Using a set * should be more performant for enums with around 52 or more elements. */ export declare function assertEnumValue(value: number | string, transpiledEnum: T, msg: string, set?: ReadonlySet): asserts value is T[keyof T]; /** Helper function to throw an error if the provided value is not an integer. */ export declare function assertInteger(value: unknown, msg: string): asserts value is number; /** * Helper function to throw an error if the provided value is not an instance of the expected class. * * This is useful to have TypeScript narrow a value to a specific type in a concise way. */ export declare function assertIs unknown>(value: unknown, constructor: T, msg: string): asserts value is InstanceType; /** * Helper function to throw an error if the provided value is equal to `null`. * * This is useful to have TypeScript narrow a `T | null` value to `T` in a concise way. */ export declare function assertNotNull(value: T, ...[msg]: [null] extends [T] ? [string] : [ "The assertion is useless because the provided value does not contain null." ]): asserts value is Exclude; /** Helper function to throw an error if the provided value is not a number. */ export declare function assertNumber(value: T, ...[msg]: [T] extends [number] ? [ "The assertion is useless because the provided value is already a number." ] : [string]): asserts value is T & number; /** * Helper function to throw an error if the provided value is not an object (i.e., a TypeScript * record). * * This is useful to have TypeScript narrow a `Record | undefined` value to * `Record` in a concise way. * * Under the hood, this function uses the `isObject` helper function. */ export declare function assertObject(value: T, ...[msg]: [T] extends [Record] ? [ "The assertion is useless because the provided value is already an object." ] : [string]): asserts value is T & Record; /** Helper function to throw an error if the provided value is not a positive integer. */ export declare function assertPositiveInteger(value: unknown, msg: string): asserts value is number; /** Helper function to throw an error if the provided value is not a string. */ export declare function assertString(value: T, ...[msg]: [T] extends [string] ? [ "The assertion is useless because the provided value is already a string." ] : [string]): asserts value is T & string; /** Helper function to throw an error if the provided value is not a string or an empty string. */ export declare function assertStringNotEmpty(value: unknown, msg: string): asserts value is string; //# sourceMappingURL=assert.d.ts.map