import type { MergeParameters } from './versionedTypes'; export type { MergeParameters } from './versionedTypes'; /** A standard selector function, which takes three generic type arguments: * @param State The first value, often a Redux root state object * @param Result The final result returned by the selector * @param Params All additional arguments passed into the selector */ export type Selector = [Params] extends [never] ? (state: State) => Result : (state: State, ...params: Params) => Result; /** Selectors generated by Reselect have several additional fields attached: */ export interface OutputSelectorFields { /** The final function passed to `createSelector` */ resultFunc: Combiner; /** The same function, memoized */ memoizedResultFunc: Combiner & Keys; /** Returns the last result calculated by the selector */ lastResult: () => ReturnType; /** An array of the input selectors */ dependencies: SelectorArray; /** Counts the number of times the output has been recalculated */ recomputations: () => number; /** Resets the count of recomputations count to 0 */ resetRecomputations: () => number; } /** Represents the actual selectors generated by `createSelector`. * The selector is: * - "a function that takes this state + params and returns a result" * - plus the attached additional fields */ export type OutputSelector Keys = {}> = Selector, Result, Params> & OutputSelectorFields; /** A selector that is assumed to have one additional argument, such as * the props from a React component */ export type ParametricSelector = Selector; /** A generated selector that is assumed to have one additional argument */ export type OutputParametricSelector = ParametricSelector & OutputSelectorFields; /** An array of input selectors */ export type SelectorArray = ReadonlyArray; /** A standard function returning true if two values are considered equal */ export type EqualityFn = (a: any, b: any) => boolean; /** Extracts an array of all return types from all input selectors */ export type SelectorResultArray = ExtractReturnType; /** Determines the combined single "State" type (first arg) from all input selectors */ export type GetStateFromSelectors = MergeParameters[0]; /** Determines the combined "Params" type (all remaining args) from all input selectors */ export type GetParamsFromSelectors>> = RemainingItems; /** Any function with arguments */ export type UnknownFunction = (...args: any[]) => any; /** Extract the return type from all functions as a tuple */ export type ExtractReturnType = { [index in keyof T]: T[index] extends T[number] ? ReturnType : never; }; /** First item in an array */ export type Head = T extends [any, ...any[]] ? T[0] : never; /** All other items in an array */ export type Tail = A extends [any, ...infer Rest] ? Rest : never; /** Last item in an array. Recursion also enables this to work with rest syntax - where the type of rest is extracted */ export type ReverseHead = Tail extends [ unknown ] ? S : Tail extends readonly unknown[][] ? ReverseHead> : never; /** All elements in array except last * * Recursion makes this work also when rest syntax has been used * Runs _ReverseTail twice, because first pass turns last element into "never", and second pass removes it. **/ export type ReverseTail = _ReverseTail<_ReverseTail>; type _ReverseTail = Tail extends [unknown] ? [Head] : Tail extends unknown[] ? [Head, ..._ReverseTail>] : never; /** Extract only numeric keys from an array type */ export type AllArrayKeys = A extends any ? { [K in keyof A]: K; }[number] : never; export type List = ReadonlyArray; export type Has = [U1] extends [U] ? 1 : 0; /** The infamous "convert a union type to an intersection type" hack * Source: https://github.com/sindresorhus/type-fest/blob/main/source/union-to-intersection.d.ts * Reference: https://github.com/microsoft/TypeScript/issues/29594 */ export type UnionToIntersection = (Union extends unknown ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection : never; /** * Assorted util types for type-level conditional logic * Source: https://github.com/KiaraGrouwstra/typical */ export type Bool = '0' | '1'; export type Obj = { [k: string]: T; }; export type And = ({ 1: { 1: '1'; } & Obj<'0'>; } & Obj>)[A][B]; export type Matches = V extends T ? '1' : '0'; export type IsArrayType = Matches; export type Not = { '1': '0'; '0': '1'; }[T]; export type InstanceOf = And, Not>>; export type IsTuple = And, InstanceOf>; /** * Code to convert a union of values into a tuple. * Source: https://stackoverflow.com/a/55128956/62937 */ type Push = [...T, V]; type LastOf = UnionToIntersection T : never> extends () => infer R ? R : never; export type TuplifyUnion, N = [T] extends [never] ? true : false> = true extends N ? [] : Push>, L>; /** * Converts "the values of an object" into a tuple, like a type-level `Object.values()` * Source: https://stackoverflow.com/a/68695508/62937 */ export type ObjValueTuple, R extends any[] = []> = KS extends [infer K, ...infer KT] ? ObjValueTuple : R; /** Utility type to infer the type of "all params of a function except the first", so we can determine what arguments a memoize function accepts */ export type DropFirst = T extends [unknown, ...infer U] ? U : never; /** * Expand an item a single level, or recursively. * Source: https://stackoverflow.com/a/69288824/62937 */ export type Expand = T extends (...args: infer A) => infer R ? (...args: Expand) => Expand : T extends infer O ? { [K in keyof O]: O[K]; } : never; 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; type Identity = T; /** * Another form of type value expansion * Source: https://github.com/microsoft/TypeScript/issues/35247 */ export type Mapped = Identity<{ [k in keyof T]: T[k]; }>; export type If2 = B extends 1 ? Then : Else; export type Boolean2 = 0 | 1; export type Key = string | number | symbol; export type BuiltIn = Function | Error | Date | { readonly [Symbol.toStringTag]: string; } | RegExp | Generator;