import type { FlatType, TupleToIntersection, Writable } from "./_typeutil.js"; import { type GetMetadata, type WithMetadata } from "./metadata.js"; /** * A type predicate function. */ export type Predicate = (x: unknown) => x is T; /** * A type predicated by Predicate. * * ```ts * import { is, type PredicateType } from "@core/unknownutil"; * * const isPerson = is.ObjectOf({ * name: is.String, * age: is.Number, * address: is.OptionalOf(is.String), * }); * * type Person = PredicateType; * // Above is equivalent to the following type * // type Person = { * // name: string; * // age: number; * // address: string | undefined; * // }; */ export type PredicateType

= P extends Predicate ? T : never; /** * Assume `x is `any` and always return `true` regardless of the type of `x`. * * ```ts * import { is } from "@core/unknownutil"; * * const a = "a"; * if (is.Any(a)) { * // a is narrowed to any * const _: any = a; * } * ``` */ export declare function isAny(_x: unknown): _x is any; /** * Assume `x` is `unknown` and always return `true` regardless of the type of `x`. * * ```ts * import { is } from "@core/unknownutil"; * * const a = "a"; * if (is.Unknown(a)) { * // a is narrowed to unknown * const _: unknown = a; * } * ``` */ export declare function isUnknown(_x: unknown): _x is unknown; /** * Return `true` if the type of `x` is `string`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = "a"; * if (is.String(a)) { * // a is narrowed to string * const _: string = a; * } * ``` */ export declare function isString(x: unknown): x is string; /** * Return `true` if the type of `x` is `number`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = 0; * if (is.Number(a)) { * // a is narrowed to number * const _: number = a; * } * ``` */ export declare function isNumber(x: unknown): x is number; /** * Return `true` if the type of `x` is `bigint`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = 0n; * if (is.BigInt(a)) { * // a is narrowed to bigint * const _: bigint = a; * } * ``` */ export declare function isBigInt(x: unknown): x is bigint; /** * Return `true` if the type of `x` is `boolean`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = true; * if (is.Boolean(a)) { * // a is narrowed to boolean * const _: boolean = a; * } * ``` */ export declare function isBoolean(x: unknown): x is boolean; /** * Return `true` if the type of `x` is `unknown[]`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = [0, 1, 2]; * if (is.Array(a)) { * // a is narrowed to unknown[] * const _: unknown[] = a; * } * ``` */ export declare function isArray(x: unknown): x is unknown[]; /** * Return `true` if the type of `x` is `Set`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = new Set([0, 1, 2]); * if (is.Set(a)) { * // a is narrowed to Set * const _: Set = a; * } * ``` */ export declare function isSet(x: unknown): x is Set; /** * Return `true` if the type of `x` is an object instance that satisfies `Record`. * * Note that this function check if the `x` is an instance of `Object`. * Use `isRecordLike` instead if you want to check if the `x` satisfies the `Record` type. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = {"a": 0, "b": 1}; * if (is.RecordObject(a)) { * // a is narrowed to Record * const _: Record = a; * } * * const b: unknown = new Set(); * if (is.RecordObject(b)) { * // b is not a raw object, so it is not narrowed * } * ``` */ export declare function isRecordObject(x: unknown): x is Record; /** * Return `true` if the type of `x` satisfies `Record`. * * Note that this function returns `true` for ambiguous instances like `Set`, `Map`, `Date`, `Promise`, etc. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = {"a": 0, "b": 1}; * if (is.Record(a)) { * // a is narrowed to Record * const _: Record = a; * } * * const b: unknown = new Set(); * if (is.Record(b)) { * // b is narrowed to Record * const _: Record = b; * } * ``` */ export declare function isRecord(x: unknown): x is Record; /** * Return `true` if the type of `x` is like `Record`. * * @deprecated Use `is.Record` instead. * ``` */ export declare function isRecordLike(x: unknown): x is Record; /** * Return `true` if the type of `x` is `Map`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = new Map([["a", 0], ["b", 1]]); * if (is.Map(a)) { * // a is narrowed to Map * const _: Map = a; * } * ``` */ export declare function isMap(x: unknown): x is Map; /** * Return `true` if the type of `x` is `function`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = () => {}; * if (is.Function(a)) { * // a is narrowed to (...args: unknown[]) => unknown * const _: ((...args: unknown[]) => unknown) = a; * } * ``` */ export declare function isFunction(x: unknown): x is (...args: unknown[]) => unknown; /** * Return `true` if the type of `x` is `function` (non async function). * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = () => {}; * if (is.Function(a)) { * // a is narrowed to (...args: unknown[]) => unknown * const _: ((...args: unknown[]) => unknown) = a; * } * ``` */ export declare function isSyncFunction(x: unknown): x is (...args: unknown[]) => unknown; /** * Return `true` if the type of `x` is `function` (async function). * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = async () => {}; * if (is.Function(a)) { * // a is narrowed to (...args: unknown[]) => Promise * const _: ((...args: unknown[]) => unknown) = a; * } * ``` */ export declare function isAsyncFunction(x: unknown): x is (...args: unknown[]) => Promise; /** * Return `true` if the type of `x` is `null`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = null; * if (is.Null(a)) { * // a is narrowed to null * const _: null = a; * } * ``` */ export declare function isNull(x: unknown): x is null; /** * Return `true` if the type of `x` is `undefined`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = undefined; * if (is.Undefined(a)) { * // a is narrowed to undefined * const _: undefined = a; * } * ``` */ export declare function isUndefined(x: unknown): x is undefined; /** * Return `true` if the type of `x` is `null` or `undefined`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = null; * if (is.Nullish(a)) { * // a is narrowed to null | undefined * const _: (null | undefined) = a; * } * ``` */ export declare function isNullish(x: unknown): x is null | undefined; /** * Return `true` if the type of `x` is `symbol`. * * ```ts * import { is } from "@core/unknownutil"; * * const a: unknown = Symbol("symbol"); * if (is.Symbol(a)) { * // a is narrowed to symbol * const _: symbol = a; * } * ``` */ export declare function isSymbol(x: unknown): x is symbol; export type Primitive = string | number | bigint | boolean | null | undefined | symbol; /** * Return `true` if the type of `x` is `Primitive`. * * ```ts * import { is, Primitive } from "@core/unknownutil"; * * const a: unknown = 0; * if (is.Primitive(a)) { * // a is narrowed to Primitive * const _: Primitive = a; * } * ``` */ export declare function isPrimitive(x: unknown): x is Primitive; /** * Return `true` if the type of predicate function `x` is annotated as `Optional` */ export declare function isOptional

>(x: P): x is P & WithMetadata; /** * Return an `Optional` annotated type predicate function that returns `true` if the type of `x` is `T` or `undefined`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.OptionalOf(is.String); * const a: unknown = "a"; * if (isMyType(a)) { * // a is narrowed to string | undefined * const _: string | undefined = a; * } * ``` */ export declare function isOptionalOf(pred: Predicate): Predicate & WithMetadata; type IsOptionalOfMetadata = { name: "isOptionalOf"; args: Parameters; }; /** * Return an `Optional` un-annotated type predicate function that returns `true` if the type of `x` is `T`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.UnwrapOptionalOf(is.OptionalOf(is.String)); * const a: unknown = "a"; * if (isMyType(a)) { * // a is narrowed to string * const _: string = a; * } * ``` */ export declare function isUnwrapOptionalOf

>(pred: P): UnwrapOptionalOf

; type UnwrapOptionalOf = T extends Predicate & WithMetadata ? Predicate : T extends Predicate ? T : never; /** * Return `true` if the type of predicate function `x` is annotated as `Readonly` * * **This is unstable and may be removed in the future.** */ export declare function isReadonly

>(x: P): x is P & WithMetadata; /** * Return an `Readonly` annotated type predicate function that returns `true` if the type of `x` is `T`. * * **This is unstable and may be removed in the future.** * * Note that this function does nothing but annotate the predicate function as `Readonly`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.ReadonlyOf(is.TupleOf([is.String, is.Number])); * const a: unknown = ["a", 1]; * if (isMyType(a)) { * // a is narrowed to readonly [string, number] * const _: readonly [string, number] = a; * } * ``` */ export declare function isReadonlyOf(pred: Predicate): Predicate> & WithMetadata; type IsReadonlyOfMetadata = { name: "isReadonlyOf"; args: Parameters; }; /** * Return an `Readonly` un-annotated type predicate function that returns `true` if the type of `x` is `T`. * * **This is unstable and may be removed in the future.** * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.UnwrapReadonlyOf(is.ReadonlyOf(is.TupleOf([is.String, is.Number]))); * const a: unknown = ["a", 1]; * if (isMyType(a)) { * // a is narrowed to [string, number] * const _: [string, number] = a; * } * ``` */ export declare function isUnwrapReadonlyOf

>(pred: P): UnwrapReadonlyOf

; type UnwrapReadonlyOf = T extends Predicate & WithMetadata ? Predicate> : T extends Predicate ? T : never; /** * Return a type predicate function that returns `true` if the type of `x` is `T[]`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.ArrayOf(is.String); * const a: unknown = ["a", "b", "c"]; * if (isMyType(a)) { * // a is narrowed to string[] * const _: string[] = a; * } * ``` */ export declare function isArrayOf(pred: Predicate): Predicate & WithMetadata; type IsArrayOfMetadata = { name: "isArrayOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` is `Set`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.SetOf(is.String); * const a: unknown = new Set(["a", "b", "c"]); * if (isMyType(a)) { * // a is narrowed to Set * const _: Set = a; * } * ``` */ export declare function isSetOf(pred: Predicate): Predicate> & WithMetadata; type IsSetOfMetadata = { name: "isSetOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` is `TupleOf` or `TupleOf`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.TupleOf([is.Number, is.String, is.Boolean]); * const a: unknown = [0, "a", true]; * if (isMyType(a)) { * // a is narrowed to [number, string, boolean] * const _: [number, string, boolean] = a; * } * ``` * * With `predElse`: * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.TupleOf( * [is.Number, is.String, is.Boolean], * is.ArrayOf(is.Number), * ); * const a: unknown = [0, "a", true, 0, 1, 2]; * if (isMyType(a)) { * // a is narrowed to [number, string, boolean, ...number[]] * const _: [number, string, boolean, ...number[]] = a; * } * ``` * * Depending on the version of TypeScript and how values are provided, it may be necessary to add `as const` to the array * used as `predTup`. If a type error occurs, try adding `as const` as follows: * * ```ts * import { is } from "@core/unknownutil"; * * const predTup = [is.Number, is.String, is.Boolean] as const; * const isMyType = is.TupleOf(predTup); * const a: unknown = [0, "a", true]; * if (isMyType(a)) { * // a is narrowed to [number, string, boolean] * const _: [number, string, boolean] = a; * } * ``` */ export declare function isTupleOf, ...Predicate[]]>(predTup: T): Predicate> & WithMetadata; export declare function isTupleOf, ...Predicate[]], E extends Predicate>(predTup: T, predElse: E): Predicate<[...TupleOf, ...PredicateType]> & WithMetadata; type TupleOf = { -readonly [P in keyof T]: T[P] extends Predicate ? U : never; }; type IsTupleOfMetadata = { name: "isTupleOf"; args: [Parameters[0], Parameters[1]?]; }; /** * Return a type predicate function that returns `true` if the type of `x` is `ParametersOf` or `ParametersOf`. * * This is similar to `TupleOf` or `TupleOf`, but if `is.OptionalOf()` is specified at the trailing, the trailing elements becomes optional and makes variable-length tuple. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.ParametersOf([ * is.Number, * is.OptionalOf(is.String), * is.Boolean, * is.OptionalOf(is.Number), * is.OptionalOf(is.String), * is.OptionalOf(is.Boolean), * ] as const); * const a: unknown = [0, undefined, "a"]; * if (isMyType(a)) { * // a is narrowed to [number, string | undefined, boolean, number?, string?, boolean?] * const _: [number, string | undefined, boolean, number?, string?, boolean?] = a; * } * ``` * * With `predElse`: * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.ParametersOf( * [ * is.Number, * is.OptionalOf(is.String), * is.OptionalOf(is.Boolean), * ] as const, * is.ArrayOf(is.Number), * ); * const a: unknown = [0, "a", true, 0, 1, 2]; * if (isMyType(a)) { * // a is narrowed to [number, string?, boolean?, ...number[]] * const _: [number, string?, boolean?, ...number[]] = a; * } * ``` * * Depending on the version of TypeScript and how values are provided, it may be necessary to add `as const` to the array * used as `predTup`. If a type error occurs, try adding `as const` as follows: * * ```ts * import { is } from "@core/unknownutil"; * * const predTup = [is.Number, is.String, is.OptionalOf(is.Boolean)] as const; * const isMyType = is.ParametersOf(predTup); * const a: unknown = [0, "a"]; * if (isMyType(a)) { * // a is narrowed to [number, string, boolean?] * const _: [number, string, boolean?] = a; * } * ``` */ export declare function isParametersOf[]]>(predTup: T): Predicate> & WithMetadata; export declare function isParametersOf[]], E extends Predicate>(predTup: T, predElse: E): Predicate<[...ParametersOf, ...PredicateType]> & WithMetadata; type ParametersOf = T extends readonly [] ? [] : T extends readonly [...infer P, infer R] ? P extends Predicate[] ? R extends Predicate & WithMetadata ? [...ParametersOf

, PredicateType?] : [...ParametersOf

, PredicateType] : never : TupleOf; type IsParametersOfMetadata = { name: "isParametersOf"; args: [ Parameters[0], Parameters[1]? ]; }; /** * Return a type predicate function that returns `true` if the type of `x` is `Readonly>`. * * @deprecated Use `is.ReadonlyOf(is.TupleOf(...))` instead. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.ReadonlyTupleOf([is.Number, is.String, is.Boolean]); * const a: unknown = [0, "a", true]; * if (isMyType(a)) { * // a is narrowed to readonly [number, string, boolean] * const _: readonly [number, string, boolean] = a; * } * ``` * * With `predElse`: * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.ReadonlyTupleOf( * [is.Number, is.String, is.Boolean], * is.ArrayOf(is.Number), * ); * const a: unknown = [0, "a", true, 0, 1, 2]; * if (isMyType(a)) { * // a is narrowed to readonly [number, string, boolean, ...number[]] * const _: readonly [number, string, boolean, ...number[]] = a; * } * ``` * * Depending on the version of TypeScript and how values are provided, it may be necessary to add `as const` to the array * used as `predTup`. If a type error occurs, try adding `as const` as follows: * * ```ts * import { is } from "@core/unknownutil"; * * const predTup = [is.Number, is.String, is.Boolean] as const; * const isMyType = is.ReadonlyTupleOf(predTup); * const a: unknown = [0, "a", true]; * if (isMyType(a)) { * // a is narrowed to readonly [number, string, boolean] * const _: readonly [number, string, boolean] = a; * } * ``` */ export declare function isReadonlyTupleOf, ...Predicate[]]>(predTup: T): Predicate>> & WithMetadata; export declare function isReadonlyTupleOf, ...Predicate[]], E extends Predicate>(predTup: T, predElse: E): Predicate, ...PredicateType]>> & WithMetadata; /** * Return a type predicate function that returns `true` if the type of `x` is `UniformTupleOf`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.UniformTupleOf(5); * const a: unknown = [0, 1, 2, 3, 4]; * if (isMyType(a)) { * // a is narrowed to [unknown, unknown, unknown, unknown, unknown] * const _: [unknown, unknown, unknown, unknown, unknown] = a; * } * ``` * * With predicate function: * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.UniformTupleOf(5, is.Number); * const a: unknown = [0, 1, 2, 3, 4]; * if (isMyType(a)) { * // a is narrowed to [number, number, number, number, number] * const _: [number, number, number, number, number] = a; * } * ``` */ export declare function isUniformTupleOf(n: N, pred?: Predicate): Predicate> & WithMetadata; type UniformTupleOf = R["length"] extends N ? R : UniformTupleOf; type IsUniformTupleOfMetadata = { name: "isUniformTupleOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` is `Readonly>`. * * @deprecated Use `is.ReadonlyOf(is.UniformTupleOf(...))` instead. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.ReadonlyUniformTupleOf(5); * const a: unknown = [0, 1, 2, 3, 4]; * if (isMyType(a)) { * // a is narrowed to readonly [unknown, unknown, unknown, unknown, unknown] * const _: readonly [unknown, unknown, unknown, unknown, unknown] = a; * } * ``` * * With predicate function: * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.ReadonlyUniformTupleOf(5, is.Number); * const a: unknown = [0, 1, 2, 3, 4]; * if (isMyType(a)) { * // a is narrowed to readonly [number, number, number, number, number] * const _: readonly [number, number, number, number, number] = a; * } * ``` */ export declare function isReadonlyUniformTupleOf(n: N, pred?: Predicate): Predicate>> & WithMetadata; /** * Return a type predicate function that returns `true` if the type of `x` is an Object instance that satisfies `Record`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * Note that this function check if the `x` is an instance of `Object`. * Use `isRecordOf` instead if you want to check if the `x` satisfies the `Record` type. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.RecordObjectOf(is.Number); * const a: unknown = {"a": 0, "b": 1}; * if (isMyType(a)) { * // a is narrowed to Record * const _: Record = a; * } * ``` * * With predicate function for keys: * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.RecordObjectOf(is.Number, is.String); * const a: unknown = {"a": 0, "b": 1}; * if (isMyType(a)) { * // a is narrowed to Record * const _: Record = a; * } * ``` */ export declare function isRecordObjectOf(pred: Predicate, predKey?: Predicate): Predicate> & WithMetadata; type IsRecordObjectOfMetadata = { name: "isRecordObjectOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` satisfies `Record`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.RecordOf(is.Number); * const a: unknown = {"a": 0, "b": 1}; * if (isMyType(a)) { * // a is narrowed to Record * const _: Record = a; * } * ``` * * With predicate function for keys: * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.RecordOf(is.Number, is.String); * const a: unknown = {"a": 0, "b": 1}; * if (isMyType(a)) { * // a is narrowed to Record * const _: Record = a; * } * ``` */ export declare function isRecordOf(pred: Predicate, predKey?: Predicate): Predicate> & WithMetadata; type IsRecordOfMetadata = { name: "isRecordOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` satisfies `Record`. * * @deprecated Use `is.RecordOf()` instead */ export declare function isRecordLikeOf(pred: Predicate, predKey?: Predicate): Predicate> & WithMetadata; type IsRecordLikeOfMetadata = { name: "isRecordLikeOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` is `Map`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.MapOf(is.Number); * const a: unknown = new Map([["a", 0], ["b", 1]]); * if (isMyType(a)) { * // a is narrowed to Map * const _: Map = a; * } * ``` * * With predicate function for keys: * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.MapOf(is.Number, is.String); * const a: unknown = new Map([["a", 0], ["b", 1]]); * if (isMyType(a)) { * // a is narrowed to Map * const _: Map = a; * } * ``` */ export declare function isMapOf(pred: Predicate, predKey?: Predicate): Predicate> & WithMetadata; type IsMapOfMetadata = { name: "isMapOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` is `ObjectOf`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * If `is.OptionalOf()` is specified in the predicate function, the property becomes optional. * * The number of keys of `x` must be greater than or equal to the number of keys of `predObj`. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.ObjectOf({ * a: is.Number, * b: is.String, * c: is.OptionalOf(is.Boolean), * }); * const a: unknown = { a: 0, b: "a", other: "other" }; * if (isMyType(a)) { * // "other" key in `a` is ignored because of `options.strict` is `false`. * // a is narrowed to { a: number; b: string; c?: boolean | undefined } * const _: { a: number; b: string; c?: boolean | undefined } = a; * } * ``` */ export declare function isObjectOf>>(predObj: T): Predicate> & WithMetadata; /** * @deprecated The `option.strict` is deprecated. Use `isStrictOf()` instead. */ export declare function isObjectOf>>(predObj: T, options: { strict?: boolean; }): Predicate> & WithMetadata; type WithOptional = WithMetadata>> | { optional: true; }; type ObjectOf>> = FlatType<{ [K in keyof T as T[K] extends WithOptional ? never : K]: T[K] extends Predicate ? U : never; } & { [K in keyof T as T[K] extends WithOptional ? K : never]?: T[K] extends Predicate ? U : never; }>; type IsObjectOfMetadata = { name: "isObjectOf"; args: [Parameters[0]]; }; /** * Return a type predicate function that returns `true` if the type of `x` is strictly follow the `ObjectOf`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * If `is.OptionalOf()` is specified in the predicate function, the property becomes optional. * * The number of keys of `x` must be equal to the number of non optional keys of `predObj`. This is equivalent to * the deprecated `options.strict` in `isObjectOf()`. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.StrictOf(is.ObjectOf({ * a: is.Number, * b: is.String, * c: is.OptionalOf(is.Boolean), * })); * const a: unknown = { a: 0, b: "a", other: "other" }; * if (isMyType(a)) { * // This block will not be executed because of "other" key in `a`. * } * ``` */ export declare function isStrictOf>(pred: Predicate & WithMetadata): Predicate & WithMetadata; type IsStrictOfMetadata = { name: "isStrictOf"; args: Parameters; }; /** * Return `true` if the type of `x` is instance of `ctor`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.InstanceOf(Date); * const a: unknown = new Date(); * if (isMyType(a)) { * // a is narrowed to Date * const _: Date = a; * } * ``` */ export declare function isInstanceOf unknown>(ctor: T): Predicate> & WithMetadata; type IsInstanceOfMetadata = { name: "isInstanceOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` is a literal type of `pred`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.LiteralOf("hello"); * const a: unknown = "hello"; * if (isMyType(a)) { * // a is narrowed to "hello" * const _: "hello" = a; * } * ``` */ export declare function isLiteralOf(literal: T): Predicate & WithMetadata; type IsLiteralOfMetadata = { name: "isLiteralOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` is one of literal type in `preds`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.LiteralOneOf(["hello", "world"] as const); * const a: unknown = "hello"; * if (isMyType(a)) { * // a is narrowed to "hello" | "world" * const _: "hello" | "world" = a; * } * ``` */ export declare function isLiteralOneOf(literals: T): Predicate & WithMetadata; type IsLiteralOneOfMetadata = { name: "isLiteralOneOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` is `UnionOf`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.UnionOf([is.Number, is.String, is.Boolean]); * const a: unknown = 0; * if (isMyType(a)) { * // a is narrowed to number | string | boolean * const _: number | string | boolean = a; * } * ``` * * Depending on the version of TypeScript and how values are provided, it may be necessary to add `as const` to the array * used as `preds`. If a type error occurs, try adding `as const` as follows: * * ```ts * import { is } from "@core/unknownutil"; * * const preds = [is.Number, is.String, is.Boolean] as const; * const isMyType = is.UnionOf(preds); * const a: unknown = 0; * if (isMyType(a)) { * // a is narrowed to number | string | boolean * const _: number | string | boolean = a; * } * ``` */ export declare function isUnionOf, ...Predicate[]]>(preds: T): Predicate> & WithMetadata; type UnionOf = T extends readonly [Predicate, ...infer R] ? U | UnionOf : never; type IsUnionOfMetadata = { name: "isUnionOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` is `IntersectionOf`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```ts * import { is } from "@core/unknownutil"; * * const isMyType = is.IntersectionOf([ * is.ObjectOf({ a: is.Number }), * is.ObjectOf({ b: is.String }), * ]); * const a: unknown = { a: 0, b: "a" }; * if (isMyType(a)) { * // a is narrowed to { a: number } & { b: string } * const _: { a: number } & { b: string } = a; * } * ``` * * Depending on the version of TypeScript and how values are provided, it may be necessary to add `as const` to the array * used as `preds`. If a type error occurs, try adding `as const` as follows: * * ```ts * import { is } from "@core/unknownutil"; * * const preds = [ * is.ObjectOf({ a: is.Number }), * is.ObjectOf({ b: is.String }), * ] as const * const isMyType = is.IntersectionOf(preds); * const a: unknown = { a: 0, b: "a" }; * if (isMyType(a)) { * // a is narrowed to { a: number } & { b: string } * const _: { a: number } & { b: string } = a; * } * ``` */ export declare function isIntersectionOf & WithMetadata, ...(Predicate & WithMetadata)[] ]>(preds: T): Predicate> & WithMetadata; export declare function isIntersectionOf]>(preds: T): T[0]; export declare function isIntersectionOf, ...Predicate[]]>(preds: T): Predicate> & WithMetadata; type IntersectionOf = TupleToIntersection>; type IsIntersectionOfMetadata = { name: "isIntersectionOf"; args: Parameters; }; /** * Return a type predicate function that returns `true` if the type of `x` is `Required>`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```typescript * import { is } from "@core/unknownutil"; * * const isMyType = is.RequiredOf(is.ObjectOf({ * a: is.Number, * b: is.UnionOf([is.String, is.Undefined]), * c: is.OptionalOf(is.Boolean), * })); * const a: unknown = { a: 0, b: "b", c: true, other: "other" }; * if (isMyType(a)) { * // 'a' is narrowed to { a: number; b: string | undefined; c: boolean } * const _: { a: number; b: string | undefined; c: boolean } = a; * } * ``` */ export declare function isRequiredOf>(pred: Predicate & WithMetadata): Predicate>> & WithMetadata; /** * Return a type predicate function that returns `true` if the type of `x` is `Partial>`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```typescript * import { is } from "@core/unknownutil"; * * const isMyType = is.PartialOf(is.ObjectOf({ * a: is.Number, * b: is.UnionOf([is.String, is.Undefined]), * c: is.OptionalOf(is.Boolean), * })); * const a: unknown = { a: undefined, other: "other" }; * if (isMyType(a)) { * // The "other" key in `a` is ignored. * // 'a' is narrowed to { a?: number | undefined; b?: string | undefined; c?: boolean | undefined } * const _: { a?: number | undefined; b?: string | undefined; c?: boolean | undefined } = a; * } * ``` */ export declare function isPartialOf>(pred: Predicate & WithMetadata): Predicate>> & WithMetadata; /** * Return a type predicate function that returns `true` if the type of `x` is `Pick, K>`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```typescript * import { is } from "@core/unknownutil"; * * const isMyType = is.PickOf(is.ObjectOf({ * a: is.Number, * b: is.String, * c: is.OptionalOf(is.Boolean), * }), ["a", "c"]); * const a: unknown = { a: 0, b: "a", other: "other" }; * if (isMyType(a)) { * // The "b" and "other" key in `a` is ignored. * // 'a' is narrowed to { a: number; c?: boolean | undefined } * const _: { a: number; c?: boolean | undefined } = a; * } * ``` */ export declare function isPickOf, K extends keyof T>(pred: Predicate & WithMetadata, keys: K[]): Predicate>> & WithMetadata; /** * Return a type predicate function that returns `true` if the type of `x` is `Omit, K>`. * * To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost. * * ```typescript * import { is } from "@core/unknownutil"; * * const isMyType = is.OmitOf(is.ObjectOf({ * a: is.Number, * b: is.String, * c: is.OptionalOf(is.Boolean), * }), ["a", "c"]); * const a: unknown = { a: 0, b: "a", other: "other" }; * if (isMyType(a)) { * // The "a", "c", and "other" key in `a` is ignored. * // 'a' is narrowed to { b: string } * const _: { b: string } = a; * } * ``` */ export declare function isOmitOf, K extends keyof T>(pred: Predicate & WithMetadata, keys: K[]): Predicate>> & WithMetadata; /** * Return a type predicate function that returns `true` if the type of `x` is `UnionOf`. * * @deprecated Use `isUnionOf` instead. */ export declare function isOneOf, ...Predicate[]]>(preds: T): Predicate>; type OneOf = T extends readonly [Predicate, ...infer R] ? U | OneOf : never; /** * Return a type predicate function that returns `true` if the type of `x` is `IntersectionOf`. * * @deprecated Use `isIntersectionOf` instead. */ export declare function isAllOf & WithMetadata, ...(Predicate & WithMetadata)[] ]>(preds: T): Predicate>; type AllOf = IntersectionOf; export declare const is: { AllOf: typeof isAllOf; Any: typeof isAny; Array: typeof isArray; ArrayOf: typeof isArrayOf; AsyncFunction: typeof isAsyncFunction; BigInt: typeof isBigInt; Boolean: typeof isBoolean; Function: typeof isFunction; InstanceOf: typeof isInstanceOf; IntersectionOf: typeof isIntersectionOf; LiteralOf: typeof isLiteralOf; LiteralOneOf: typeof isLiteralOneOf; Map: typeof isMap; MapOf: typeof isMapOf; Null: typeof isNull; Nullish: typeof isNullish; Number: typeof isNumber; ObjectOf: typeof isObjectOf; OmitOf: typeof isOmitOf; OneOf: typeof isOneOf; Optional: typeof isOptional; OptionalOf: typeof isOptionalOf; ParametersOf: typeof isParametersOf; PartialOf: typeof isPartialOf; PickOf: typeof isPickOf; Primitive: typeof isPrimitive; Readonly: typeof isReadonly; ReadonlyOf: typeof isReadonlyOf; ReadonlyTupleOf: typeof isReadonlyTupleOf; ReadonlyUniformTupleOf: typeof isReadonlyUniformTupleOf; Record: typeof isRecord; RecordLike: typeof isRecordLike; RecordLikeOf: typeof isRecordLikeOf; RecordObject: typeof isRecordObject; RecordObjectOf: typeof isRecordObjectOf; RecordOf: typeof isRecordOf; RequiredOf: typeof isRequiredOf; Set: typeof isSet; SetOf: typeof isSetOf; StrictOf: typeof isStrictOf; String: typeof isString; Symbol: typeof isSymbol; SyncFunction: typeof isSyncFunction; TupleOf: typeof isTupleOf; Undefined: typeof isUndefined; UniformTupleOf: typeof isUniformTupleOf; UnionOf: typeof isUnionOf; Unknown: typeof isUnknown; UnwrapOptionalOf: typeof isUnwrapOptionalOf; UnwrapReadonlyOf: typeof isUnwrapReadonlyOf; }; export {}; //# sourceMappingURL=is.d.ts.map