import { AnyArray, AnyConstructor, AnyFunction, AnyJson, JsonArray, JsonMap, Many, Optional, View, Dictionary } from '../types'; /** * Tests whether a value of type `T` contains one or more property `keys`. If so, the type of the tested value is * narrowed to reflect the existence of those keys for convenient access in the same scope. Returns false if the * property key does not exist on the target type, which must be an object. Returns true if the property key exists, * even if the associated value is `undefined` or `null`. * * ``` * // type of obj -> unknown * if (has(obj, 'name')) { * // type of obj -> { name: unknown } * if (has(obj, 'data')) { * // type of obj -> { name: unknown } & { data: unknown } * } else if (has(obj, ['error', 'status'])) { * // type of obj -> { name: unknown } & { error: unknown, status: unknown } * } * } * ``` * * @param value The value to test. * @param keys One or more `string` keys to check for existence. */ export declare function has(value: T, keys: Many): value is T & object & View; /** * Tests whether a value of type `T` contains a property `key` of type `string`. If so, the type of the tested value is * narrowed to reflect the existence of that key for convenient access in the same scope. Returns `false` if the * property key does not exist on the object or the value stored by that key is not of type `string`. * * ``` * // type of obj -> unknown * if (hasString(obj, 'name')) { * // type of obj -> { name: string } * if (hasString(obj, 'message')) { * // type of obj -> { name: string } & { message: string } * } * } * ``` * * @param value The value to test. * @param keys A `string` key to check for existence. */ export declare function hasString(value: T, key: K): value is T & object & View; /** * Tests whether a value of type `T` contains a property `key` of type `number`. If so, the type of the tested value is * narrowed to reflect the existence of that key for convenient access in the same scope. Returns `false` if the * property key does not exist on the object or the value stored by that key is not of type `number`. * * ``` * // type of obj -> unknown * if (hasNumber(obj, 'offset')) { * // type of obj -> { offset: number } * if (hasNumber(obj, 'page') && hasArray(obj, 'items')) { * // type of obj -> { offset: number } & { page: number } & { items: unknown[] } * } * } * ``` * * @param value The value to test. * @param keys A `number` key to check for existence. */ export declare function hasNumber(value: T, key: K): value is T & object & View; /** * Tests whether a value of type `T` contains a property `key` of type `boolean`. If so, the type of the tested value is * narrowed to reflect the existence of that key for convenient access in the same scope. Returns `false` if the * property key does not exist on the object or the value stored by that key is not of type `boolean`. * * ``` * // type of obj -> unknown * if (hasBoolean(obj, 'enabled')) { * // type of obj -> { enabled: boolean } * if (hasBoolean(obj, 'hidden')) { * // type of obj -> { enabled: boolean } & { hidden: boolean } * } * } * ``` * * @param value The value to test. * @param keys A `boolean` key to check for existence. */ export declare function hasBoolean(value: T, key: K): value is T & object & View; /** * Tests whether a value of type `T` contains a property `key` of type `object`. If so, the type of the tested value is * narrowed to reflect the existence of that key for convenient access in the same scope. Returns `false` if the * property key does not exist on the object or the value stored by that key is not of type `object`. * * ``` * // type of obj -> unknown * if (hasNumber(obj, 'status')) { * // type of obj -> { status: number } * if (hasObject(obj, 'data')) { * // type of obj -> { status: number } & { data: object } * } else if (hasString('error')) { * // type of obj -> { status: number } & { error: string } * } * } * ``` * * @param value The value to test. * @param keys An `object` key to check for existence. */ export declare function hasObject(value: T, key: K): value is T & object & View; /** * Tests whether a value of type `T` contains a property `key` whose type tests positively when tested with * {@link isPlainObject}. If so, the type of the tested value is narrowed to reflect the existence of that key for * convenient access in the same scope. Returns `false` if the property key does not exist on the object or the value * stored by that key is not of type `object`. * * ``` * // type of obj -> unknown * if (hasNumber(obj, 'status')) { * // type of obj -> { status: number } * if (hasPlainObject(obj, 'data')) { * // type of obj -> { status: number } & { data: object } * } else if (hasString('error')) { * // type of obj -> { status: number } & { error: string } * } * } * ``` * * @param value The value to test. * @param keys A "plain" `object` key to check for existence. */ export declare function hasPlainObject(value: T, key: K): value is T & object & View; /** * Tests whether a value of type `T` contains a property `key` whose type tests positively when tested with * {@link isDictionary}. If so, the type of the tested value is narrowed to reflect the existence of that key for * convenient access in the same scope. Returns `false` if the property key does not exist on the object or the value * stored by that key is not of type `object`. * * ``` * // type of obj -> unknown * if (hasNumber(obj, 'status')) { * // type of obj -> { status: number } * if (hasDictionary(obj, 'data')) { * // type of obj -> { status: number } & { data: Dictionary } * } else if (hasString('error')) { * // type of obj -> { status: number } & { error: string } * } * } * ``` * * @param value The value to test. * @param keys A "dictionary" `object` key to check for existence. */ export declare function hasDictionary(value: T, key: K): value is T & object & View>; /** * Tests whether a value of type `T` contains a property `key` whose type tests positively when tested with * {@link isInstance} when compared with the given constructor type `C`. If so, the type of the tested value is * narrowed to reflect the existence of that key for convenient access in the same scope. Returns `false` if the * property key does not exist on the object or the value stored by that key is not an instance of `C`. * * ``` * class ServerResponse { ... } * // type of obj -> unknown * if (hasNumber(obj, 'status')) { * // type of obj -> { status: number } * if (hasInstance(obj, 'data', ServerResponse)) { * // type of obj -> { status: number } & { data: ServerResponse } * } else if (hasString('error')) { * // type of obj -> { status: number } & { error: string } * } * } * ``` * * @param value The value to test. * @param keys An instance of type `C` key to check for existence. */ export declare function hasInstance(value: Optional, key: K, ctor: C): value is T & View>; /** * Tests whether a value of type `T` contains a property `key` of type {@link AnyArray}. If so, the type of the tested * value is narrowed to reflect the existence of that key for convenient access in the same scope. Returns `false` if * the property key does not exist on the object or the value stored by that key is not of type {@link AnyArray}. * * ``` * // type of obj -> unknown * if (hasNumber(obj, 'offset')) { * // type of obj -> { offset: number } * if (hasNumber(obj, 'page') && hasArray(obj, 'items')) { * // type of obj -> { offset: number } & { page: number } & { items: AnyArray } * } * } * ``` * * @param value The value to test. * @param keys An `AnyArray` key to check for existence. */ export declare function hasArray(value: Optional, key: K): value is T & object & View; /** * Tests whether a value of type `T` contains a property `key` of type {@link AnyFunction}. If so, the type of the * tested value is narrowed to reflect the existence of that key for convenient access in the same scope. Returns * `false` if the property key does not exist on the object or the value stored by that key is not of type * {@link AnyFunction}. * * ``` * // type of obj -> unknown * if (hasFunction(obj, 'callback')) { * // type of obj -> { callback: AnyFunction } * obj.callback(response); * } * ``` * * @param value The value to test. * @param keys An `AnyFunction` key to check for existence. */ export declare function hasFunction(value: Optional, key: K): value is T & object & View; /** * Tests whether a value of type `T` contains a property `key` of type {@link AnyJson}, _using a shallow test for * `AnyJson` compatibility_ (see {@link isAnyJson} for more information). If so, the type of the * tested value is narrowed to reflect the existence of that key for convenient access in the same scope. Returns * `false` if the property key does not exist on the object or the value stored by that key is not of type * {@link AnyJson}. * * ``` * // type of obj -> unknown * if (hasAnyJson(obj, 'body')) { * // type of obj -> { body: AnyJson } * } * ``` * * @param value The value to test. * @param keys An `AnyJson` key to check for existence. */ export declare function hasAnyJson(value: Optional, key: K): value is T & object & View; /** * Tests whether a value of type `T extends AnyJson` contains a property `key` of type {@link JsonMap}. If so, the type * of the tested value is narrowed to reflect the existence of that key for convenient access in the same scope. Returns * `false` if the property key does not exist on the object or the value stored by that key is not of type * {@link JsonMap}. * * ``` * // type of obj -> unknown * if (hasJsonMap(obj, 'body')) { * // type of obj -> { body: JsonMap } * } * ``` * * @param value The value to test. * @param keys A `JsonMap` key to check for existence. */ export declare function hasJsonMap(value: Optional, key: K): value is T & JsonMap & View; /** * Tests whether a value of type `T extends AnyJson` contains a property `key` of type {@link JsonArray}. If so, the * type of the tested value is narrowed to reflect the existence of that key for convenient access in the same scope. * Returns `false` if the property key does not exist on the object or the value stored by that key is not of type * {@link JsonArray}. * * ``` * // type of obj -> unknown * if (hasJsonArray(obj, 'body')) { * // type of obj -> { body: JsonArray } * } * ``` * * @param value The value to test. * @param keys A `JsonArray` key to check for existence. */ export declare function hasJsonArray(value: Optional, key: K): value is T & JsonMap & View;