import type {IsNever} from '../is-never'; import type {Primitive} from '../primitive'; /** Matches any primitive, `void`, `Date`, or `RegExp` value. */ export type BuiltIns = Primitive | void | Date | RegExp; /** Matches non-recursive types. */ export type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown); /** Returns a boolean for whether the two given types extends the base type. */ export type IsBothExtends = FirstType extends BaseType ? SecondType extends BaseType ? true : false : false; /** Test if the given function has multiple call signatures. Needed to handle the case of a single call signature with properties. Multiple call signatures cannot currently be supported due to a TypeScript limitation. @see https://github.com/microsoft/TypeScript/issues/29732 */ export type HasMultipleCallSignatures unknown> = T extends {(...arguments_: infer A): unknown; (...arguments_: infer B): unknown} ? B extends A ? A extends B ? false : true : true : false; /** Returns a boolean for whether the given `boolean` is not `false`. */ export type IsNotFalse = [T] extends [false] ? false : true; /** Returns a boolean for whether the given type is primitive value or primitive type. @example ``` IsPrimitive<'string'> //=> true IsPrimitive //=> true IsPrimitive //=> false ``` */ export type IsPrimitive = [T] extends [Primitive] ? true : false; /** Returns a boolean for whether A is false. @example ``` Not; //=> false Not; //=> true ``` */ export type Not = A extends true ? false : A extends false ? true : never; /** Returns a boolean for whether the given type is a union type. @example ``` type A = IsUnion; //=> true type B = IsUnion; //=> false ``` */ export type IsUnion = InternalIsUnion; /** The actual implementation of `IsUnion`. */ type InternalIsUnion = ( // @link https://ghaiklor.github.io/type-challenges-solutions/en/medium-isunion.html IsNever extends true ? false : T extends any ? [U] extends [T] ? false : true : never ) extends infer Result // In some cases `Result` will return `false | true` which is `boolean`, // that means `T` has at least two types and it's a union type, // so we will return `true` instead of `boolean`. ? boolean extends Result ? true : Result : never; // Should never happen