/** * Returns a type that a Guard will assign to a variable. * @example * ```ts * GuardType // string * GuardType // unknown[] * ``` */ declare type GuardType = Guard extends TypeGuard ? Combine : never; declare type TypeGuardSchema = { readonly [k in string]: AnyTypeGuard; }; /** * Returns a type that a Guard will extend the output of the given Guard. * @example * ```ts * GuardType // string * GuardType // unknown[] * ``` */ type PipeGuard = (value: GuardType) => value is typeof value; /** * Returns a type that a Guard will assign to a variable. * @example * ```ts * GuardType // string * GuardType // unknown[] * ``` */ declare type GuardTypeInput = Guard extends TypeGuard ? Input : never; /** * Returns a type that a Guard will assign to a variable. * Deep check on parameter/value and only return type without combining value. * @example * ```ts * GuardType // string * GuardType // unknown[] * ``` */ declare type DeepGuardType = Guard extends (value: infer X) => value is any ? Guard extends (value: X) => value is X & infer Z ? Z : GuardType : GuardType; /** * A type on which Type Guard may extend. Should be used when it can be a multi parameter guard. * @example * ```ts * * ``` */ declare type AnyIterableTypeGuard = (value: Input, index: number, values: readonly Input[]) => value is Input & Output; /** * A type on which Type Guard may extend. Should be used when it can be a multi parameter guard. * @example * ```ts * * ``` */ declare type AnyTypeGuard = (value: Input, ...args: readonly any[]) => value is Output; /** * Given a parameter and a predicate, return a new generic Type Guard that implements those */ declare type IterableTypeGuard = (value: Value, i: number, values: readonly Value[]) => value is Result extends Value ? Result : never; /** * Given a parameter and a predicate, return a new generic Type Guard that implements those */ type TypeGuard = (value: Value) => value is Result; /** * Given a parameter and a predicate, return a new generic Type Guard that implements those */ type NegateTypeGuardFn = (value: Value) => value is Exclude; /** * Given a parameter and a predicate, return a new generic Type Guard that implements those */ type NegateIterableTypeGuardFn = (value: Value, i: number, values: readonly Value[]) => value is Exclude; /** * Given the resulting Type, returns a Type Guard function */ declare type TypeGuardFn = (value: Value) => value is Combine; /** * Given the resulting Type, returns a Type Guard function */ declare type ExcludeTypeGuardFn = (value: Value | Result) => value is Exclude; /** * Given an array of Type Guards, will return the intersection of all given Guard Types. Think `GuardType` for arrays. */ declare type GuardTypes = Guards extends readonly [infer Head, ...infer Tail] ? Tail extends readonly AnyTypeGuard[] ? GuardTypes, Result>> : never : Result; /** * Given two types, will return a intersection of all the types. The difference between this and `CombineType` is that this will merge object based on keys. */ declare type Combine = B extends A ? B : A extends B ? A : { readonly [K in keyof (A & B)]-?: (A & B)[K]; } extends A & B ? { readonly [K in keyof (A & B)]-?: (A & B)[K]; } : A & B; declare type CombineObject = { readonly [K in keyof (A & B)]-?: (A & B)[K]; }; /** * Anything that may be inferred by Typescript as a primitive */ declare type AnyPrimitive = undefined | null | number | string | symbol | boolean; export type { TypeGuardSchema, AnyPrimitive, TypeGuardFn, IterableTypeGuard, NegateIterableTypeGuardFn, TypeGuard, NegateTypeGuardFn, GuardType, GuardTypeInput, AnyTypeGuard, ExcludeTypeGuardFn, GuardTypes, Combine, PipeGuard, CombineObject, DeepGuardType, AnyIterableTypeGuard };