export type ValueOf = T[keyof T]; export type MappedType = { [key in K]: V; }; export type Expand = T extends infer O ? { [K in keyof O]: O[K]; } : never; /** Return the keys of object `O` satisfying the type constraint `T` */ export type KeySatisfies = keyof { [K in keyof O as [O[K]] extends [T] ? K : never]: 1; }; /** Return the keys of object `O` which do not satisfy the type constraint `T` */ export type ExceptKeySatisfies = keyof { [K in keyof O as O[K] extends T ? never : K]: 1; }; /** * Helper for converting unions to tuples -- convert a union to an intersection using contravariance * @private */ type UnionToIntersection = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never; /** * Helper for converting unions to tuples -- extracts the last element from a union * @private */ type LastOfUnion = UnionToIntersection T : never> extends () => infer R ? R : never; /** * Helper for converting unions to tuples -- handles tail recursion with additional generics * @private */ type TailRecursiveUnionToTuple, N = [T] extends [never] ? true : false> = true extends N ? [] : [...TailRecursiveUnionToTuple>, L]; /** Converts a union type to a tuple containing all unique values from the union */ export type UnionToTuple = Expand>; /** Remove a specific value from a tuple */ export type RemoveFromTuple = T extends [ infer TFirst, ...infer TRest ] ? TFirst extends V ? RemoveFromTuple : [TFirst, ...RemoveFromTuple] : []; /** * Helper map for sorting strings * @private */ type CharOrder = { char: 'A'; order: 1; } | { char: 'B'; order: 2; } | { char: 'C'; order: 3; } | { char: 'D'; order: 4; } | { char: 'E'; order: 5; } | { char: 'F'; order: 6; } | { char: 'G'; order: 7; } | { char: 'H'; order: 8; } | { char: 'I'; order: 9; } | { char: 'J'; order: 10; } | { char: 'K'; order: 11; } | { char: 'L'; order: 12; } | { char: 'M'; order: 13; } | { char: 'N'; order: 14; } | { char: 'O'; order: 15; } | { char: 'P'; order: 16; } | { char: 'Q'; order: 17; } | { char: 'R'; order: 18; } | { char: 'S'; order: 19; } | { char: 'T'; order: 20; } | { char: 'U'; order: 21; } | { char: 'V'; order: 22; } | { char: 'W'; order: 23; } | { char: 'X'; order: 24; } | { char: 'Y'; order: 25; } | { char: 'Z'; order: 26; }; /** * Lookup for `order` value from `CharOrder` for a given character * @private */ type CharValue = Extract; }>['order']; /** * Compares two numbers by building an accumulator until its length is either `A` or `B` * @throws Will overflow if `A` and `B` are both negative. * @private */ type IsLessThan = Acc['length'] extends A ? true : Acc['length'] extends B ? false : IsLessThan; /** * Compares two string literal by character until one can be determined lexicographically smaller * @private */ type CompareStrings = A extends B ? false : A extends `${infer AFirst}${infer ARest}` ? B extends `${infer BFirst}${infer BRest}` ? AFirst extends BFirst ? CompareStrings : IsLessThan, CharValue> : false : true; /** * Helper for sorting tuples -- inserts a string into a sorted tuple * @private */ type InsertSorted = T extends [ infer TFirst extends string, ...infer TRest extends string[] ] ? CompareStrings extends true ? [U, ...T] : [TFirst, ...InsertSorted] : [U]; /** * Helper for sorting tuples -- recursively sorts a tuple of strings * @private */ type SortTuple = T extends [ infer TFirst extends string, ...infer TRest extends string[] ] ? InsertSorted, TFirst> : []; /** Converts a union type to a sorted tuple containing all unique values from the union */ export type UnionToSortedTuple = SortTuple>; export type ExtendableString = T | Omit; export {}; //# sourceMappingURL=Helpers.d.ts.map