import { AnyConstructor, AnyFunction, AnyJson, Dictionary, JsonArray, JsonMap, Nullable, Optional } from '../types'; /** * Narrows a type `Nullable` to a `T` or raises an error. * * Use of the type parameter `T` to further narrow the type signature of the value being tested is * strongly discouraged unless you are completely confident that the value is of the necessary shape to * conform with `T`. This function does nothing at either compile time or runtime to prove the value is of * shape `T`, so doing so amounts to nothing more than performing a type assertion, which is generally a * bad practice unless you have performed some other due diligence in proving that the value must be of * shape `T`. Use of the functions in the `has` co-library are useful for performing such full or partial * proofs. * * @param value The value to test. * @param message The error message to use if `value` is `undefined` or `null`. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensure(value: Nullable, message?: string): T; /** * Narrows an `unknown` value to a `string` if it is type-compatible, or raises an error otherwise. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensureString(value: unknown, message?: string): string; /** * Narrows an `unknown` value to a `number` if it is type-compatible, or raises an error otherwise. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensureNumber(value: unknown, message?: string): number; /** * Narrows an `unknown` value to a `boolean` if it is type-compatible, or raises an error otherwise. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensureBoolean(value: unknown, message?: string): boolean; /** * Narrows an `unknown` value to an `object` if it is type-compatible, or raises an error otherwise. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensureObject(value: unknown, message?: string): T; /** * Narrows an `unknown` value to an `object` if it is type-compatible and tests positively with {@link isPlainObject}, * or raises an error otherwise. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensurePlainObject(value: unknown, message?: string): T; /** * Narrows an `unknown` value to a `Dictionary` if it is type-compatible and tests positively * with {@link isDictionary}, or raises an error otherwise. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensureDictionary(value: unknown, message?: string): Dictionary; /** * Narrows an `unknown` value to instance of constructor type `T` if it is type-compatible, or raises an error * otherwise. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensureInstance(value: unknown, ctor: C, message?: string): InstanceType; /** * Narrows an `unknown` value to an `Array` if it is type-compatible, or raises an error otherwise. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensureArray(value: unknown, message?: string): T[]; /** * Narrows an `unknown` value to an `AnyFunction` if it is type-compatible, or raises an error otherwise. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensureFunction(value: unknown, message?: string): AnyFunction; /** * Narrows an `unknown` value to an `AnyJson` if it is type-compatible, or returns `undefined` otherwise. * * See also caveats noted in {@link isAnyJson}. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was not a JSON value type. */ export declare function ensureAnyJson(value: unknown, message?: string): AnyJson; /** * Narrows an `AnyJson` value to a `JsonMap` if it is type-compatible, or raises an error otherwise. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensureJsonMap(value: Optional, message?: string): JsonMap; /** * Narrows an `AnyJson` value to a `JsonArray` if it is type-compatible, or raises an error otherwise. * * @param value The value to test. * @param message The error message to use if `value` is not type-compatible. * @throws {@link UnexpectedValueTypeError} If the value was undefined. */ export declare function ensureJsonArray(value: Optional, message?: string): JsonArray;