import { UnpackArray, Func, AsyncFunc } from "./index"; /** * Defines `false` unit type if `T extends true`. * Defines `true` unit type if `T extends false`. * Defines `TIfTIsBool` when `T` is exactly `boolean` type. * * @param T Boolean type to get negation for. * @param TIfTIsBool Resulting type when `T` is exactly of `boolean` type. */ export type Not = If<(T), false, true, TIfTIsBool>; /** * Sequentially performs the following logic: * Expands to `TIfTrue` if `TCond extends true`. * Expands to `TElse` if `TCond extends false`. * Expands to `TIfCondIsBool` if `TCond extends boolean`. * * @param TCond Boolean type that controlls which branch to expand to. * @param TIfTrue Defined type if `TCond extends true` branch. * @param TElse Defined type if `TCond extends false` branch. * @param TIfCondIsBool Defined type if `TCond extends boolean`branch. */ export type If< TCond extends boolean, TIfTrue, TElse = never, TIfCondIsBool = never > = ( Extends extends true ? TIfTrue : Extends extends true ? TElse : TIfCondIsBool ); /** * Defines `true` or `false` according to the definition of `xor` logical operator. */ export type Xor = T1 extends T2 ? false : true; /** * Defines `true` or `false` according to the definition of `xnor` logical operator. */ export type Equiv = Not>; /** * Defines `true` or `false` according to the definition of `nand` logical operator. * It gets applied to all the argumets in the given tuple type `T`. */ export type Nand = Not>; /** * Defines `true` or `false` accroding to the definition of `nor` logical operator. * It gets applied to all the argumets in the given tuple type `T`. */ export type Nor = Not>; /** * Defines `true` or `false` accroding to the definition of `and` logical operator. * It gets applied to all the argumets in the given tuple type `T`. */ export type And = Not, false>>; /** * Defines `true` or `false` according to the definition of `or` logical operator. * It gets applied to all the argumets in the given tuple type `T`. */ export type Or = UnionIncludes, true>; /** * Defines `true` if `TExtender` is assignable to `TExtendee`, otherwise `false`. * @param TExtender Type to check for covariance with `TExtendee`. * @param TExtendee Type to check for contravariance with `TExtender`. * * @remarks * It verifies that you may physically assign a value of type `TExtender` to `TExtendee`. * That's why union types with excess members that are not assignable to `TExtendee` * will evaluate to `false`. */ export type Extends< TExtender, TExtendee // workaround untill this bug is resolved https://github.com/Microsoft/TypeScript/issues/30708 > = false extends (TExtender extends TExtendee ? true : false) ? false : true; /** * Shorthand for `Not>`. */ export type NotExtends = Not>; /** * Defines `true` if the given `TUnion` includes `TValue`. * This type is opposite to `UnionExcludes<>`. * * @param TUnion Union type to search for `TValue` in. * @param TValue Type to match with `TUnion` members. */ export type UnionIncludes = Extends>; /** * Defines `false` if the given `TUnion` includes `TValue`. * This type is opposite to `UnionIncludes<>`. * * @param TUnion Union type to search for `TValue` in. * @param TValue Type to match with `TUnion` members. */ export type UnionExcludes = IsNever>; /** * Defines `true` if `T1` is exactly `T2`, `false` otherwise. * Even `AreSame` expands to `false`. Only the same types expand to `true`. * Beware that this type works as vanilla `extends` clause with function types, * so comparing functions is not that strict. * * @param T1 Type to strictly compare to `T2`. * @param T2 Type to strictly compare to `T1`. */ export type AreSame = ( If<(IsAny), IsAny, If<(IsAny), IsAny, And<[ UnionIncludes, UnionIncludes, Extends, Extends ]> >> ); /** * Defines `false` if `TSuspect` is exactly of `unknown` type, `true` otherwise. * @param TSuspect Target type to check. */ export type IsNotUnknown = Not>; /** * Defines `true` if `TSuspect` is exactly of `unknown` type, `false` otherwise. * @param TSuspect Target type to check. */ export type IsUnknown = And<[IsNotAny, Extends]>; /** * Defines `false` if `TSuspect` is exactly of `any` type, `true` otherwise. * @param TSuspect Target type to check. */ export type IsNotAny = Not>; /** * Defines `true` if `TSuspect` is exactly of `any` type, `false` otherwise. * @param TSuspect Target type to check. */ export type IsAny = Extends; /** * Defines `false` if `TSuspect` is exactly of `never` type, `true` otherwise. * @param TSuspect Target type to check. */ export type IsNotNever = Not>; /** * Defines `true` if `TSuspect` is exactly of `never` type, `false` otherwise. * @param TSuspect Target type to check. */ export type IsNever = Extends; /** * Shorthand for `Extends`. * @param TSuspect Target type to check. */ export type IsFunc = Extends; /** * Shorthand for `Extends`. * @param TSuspect Target type to check. */ export type IsAsyncFunc = Extends; /** * Defines `true` if `TSuspect` contains both `undefined` and `null` types, `false` otherwise. * As a special case, defines `true` when `TSuspect` is `unknown` or `any`, * `false` if `TSuspect` is `never`. * * @param TSuspect Target type to check */ export type IsNullable = Or<[ IsUnknown, UnionIncludes ]>; /** * Defines `true` if `TSuspect` contains `null`, `false` otherwise. * As a special case, defines `true` when `TSuspect` is `unknown` or `any`, * `false` if `TSuspect` is `never`. */ export type CanBeNull = Or<[ IsUnknown, UnionIncludes ]>; /** * Defines `true` if `TSuspect` contains `undefined`, `false` otherwise. * As a special case, defines `true` when `TSuspect` is `unknown` or `any`, * `false` if `TSuspect` is `never`. */ export type CanBeUndef = Or<[ IsUnknown, UnionIncludes ]>;