import type { Push } from './array.js'; /** * Expands the type T (for intellisense and debugging) * @see https://stackoverflow.com/a/69288824/17637456 */ export type Expand = T extends (...args: infer A) => infer R ? (...args: Expand) => Expand : T extends infer O ? { [K in keyof O]: O[K]; } : never; /** * Recursivly expands the type T (for intellisense and debugging) * @see https://stackoverflow.com/a/69288824/17637456 */ export type ExpandRecursively = T extends (...args: infer A) => infer R ? (...args: ExpandRecursively) => ExpandRecursively : T extends object ? T extends infer O ? { [K in keyof O]: ExpandRecursively; } : never : T; /** * Get the keys of a union of objects * @see https://stackoverflow.com/a/65805753/17637456 */ export type UnionKeys = T extends T ? keyof T : never; type StrictUnionHelper = T extends unknown ? T & Partial, keyof T>, never>> : never; /** * @see https://stackoverflow.com/a/65805753/17637456 */ export type StrictUnion = Expand>; /** * Keys of a Map */ export type MapKeys = T extends Map ? K : never; /** * Converts a union to an intersection * @see https://stackoverflow.com/a/55128956/17637456 */ export type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; /** * Gets the last element of a union * @see https://stackoverflow.com/a/55128956/17637456 */ export type LastOfUnion = UnionToIntersection T : never> extends () => infer R ? R : never; /** * Converts a union to a tuple * @see https://stackoverflow.com/a/55128956/17637456 */ export type UnionToTuple, N = [T] extends [never] ? true : false> = true extends N ? [] : Push>, L>; /** * Utility to reduce depth of TypeScript's internal type instantiation stack. * Some wizard on the Kysely team came up with this. * It improves performance for the math types by an order of magnitude. */ export type $drain = [T] extends [unknown] ? T : never; export type Falsy = null | undefined | false | 0 | 0n | ''; /** * Returns whether `T` is `any` */ export type IsAny = 0 extends 1 & T ? true : false; export {};