1 | import type { MergeParameters } from './versionedTypes';
|
2 | export type { MergeParameters } from './versionedTypes';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export type Selector<State = any, Result = unknown, Params extends never | readonly any[] = any[]> = [Params] extends [never] ? (state: State) => Result : (state: State, ...params: Params) => Result;
|
9 |
|
10 | export interface OutputSelectorFields<Combiner extends UnknownFunction, Keys> {
|
11 |
|
12 | resultFunc: Combiner;
|
13 |
|
14 | memoizedResultFunc: Combiner & Keys;
|
15 |
|
16 | lastResult: () => ReturnType<Combiner>;
|
17 |
|
18 | dependencies: SelectorArray;
|
19 |
|
20 | recomputations: () => number;
|
21 |
|
22 | resetRecomputations: () => number;
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export type OutputSelector<S extends SelectorArray, Result, Combiner extends UnknownFunction, Params extends readonly any[] = never,
|
30 | Keys = {}> = Selector<GetStateFromSelectors<S>, Result, Params> & OutputSelectorFields<Combiner, Keys>;
|
31 |
|
32 |
|
33 |
|
34 | export type ParametricSelector<State, Props, Result> = Selector<State, Result, [
|
35 | Props,
|
36 | ...any
|
37 | ]>;
|
38 |
|
39 | export type OutputParametricSelector<State, Props, Result, Combiner extends UnknownFunction, Keys = {}> = ParametricSelector<State, Props, Result> & OutputSelectorFields<Combiner, Keys>;
|
40 |
|
41 | export type SelectorArray = ReadonlyArray<Selector>;
|
42 |
|
43 | export type EqualityFn = (a: any, b: any) => boolean;
|
44 |
|
45 | export type SelectorResultArray<Selectors extends SelectorArray> = ExtractReturnType<Selectors>;
|
46 |
|
47 | export type GetStateFromSelectors<S extends SelectorArray> = MergeParameters<S>[0];
|
48 |
|
49 | export type GetParamsFromSelectors<S extends SelectorArray, RemainingItems extends readonly unknown[] = Tail<MergeParameters<S>>> = RemainingItems;
|
50 |
|
51 | export type UnknownFunction = (...args: any[]) => any;
|
52 |
|
53 | export type ExtractReturnType<T extends readonly UnknownFunction[]> = {
|
54 | [index in keyof T]: T[index] extends T[number] ? ReturnType<T[index]> : never;
|
55 | };
|
56 |
|
57 | export type Head<T> = T extends [any, ...any[]] ? T[0] : never;
|
58 |
|
59 | export type Tail<A> = A extends [any, ...infer Rest] ? Rest : never;
|
60 |
|
61 | export type ReverseHead<S extends readonly unknown[][]> = Tail<S> extends [
|
62 | unknown
|
63 | ] ? S : Tail<S> extends readonly unknown[][] ? ReverseHead<Tail<S>> : never;
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | export type ReverseTail<S> = _ReverseTail<_ReverseTail<S>>;
|
70 | type _ReverseTail<S> = Tail<S> extends [unknown] ? [Head<S>] : Tail<S> extends unknown[] ? [Head<S>, ..._ReverseTail<Tail<S>>] : never;
|
71 |
|
72 | export type AllArrayKeys<A extends readonly any[]> = A extends any ? {
|
73 | [K in keyof A]: K;
|
74 | }[number] : never;
|
75 | export type List<A = any> = ReadonlyArray<A>;
|
76 | export type Has<U, U1> = [U1] extends [U] ? 1 : 0;
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | export type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection : never;
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | export type Bool = '0' | '1';
|
87 | export type Obj<T> = {
|
88 | [k: string]: T;
|
89 | };
|
90 | export type And<A extends Bool, B extends Bool> = ({
|
91 | 1: {
|
92 | 1: '1';
|
93 | } & Obj<'0'>;
|
94 | } & Obj<Obj<'0'>>)[A][B];
|
95 | export type Matches<V, T> = V extends T ? '1' : '0';
|
96 | export type IsArrayType<T> = Matches<T, any[]>;
|
97 | export type Not<T extends Bool> = {
|
98 | '1': '0';
|
99 | '0': '1';
|
100 | }[T];
|
101 | export type InstanceOf<V, T> = And<Matches<V, T>, Not<Matches<T, V>>>;
|
102 | export type IsTuple<T extends {
|
103 | length: number;
|
104 | }> = And<IsArrayType<T>, InstanceOf<T['length'], number>>;
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | type Push<T extends any[], V> = [...T, V];
|
110 | type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
|
111 | export type TuplifyUnion<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>;
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | export type ObjValueTuple<T, KS extends any[] = TuplifyUnion<keyof T>, R extends any[] = []> = KS extends [infer K, ...infer KT] ? ObjValueTuple<T, KT, [...R, T[K & keyof T]]> : R;
|
117 |
|
118 | export type DropFirst<T extends unknown[]> = T extends [unknown, ...infer U] ? U : never;
|
119 |
|
120 |
|
121 |
|
122 |
|
123 | export type Expand<T> = T extends (...args: infer A) => infer R ? (...args: Expand<A>) => Expand<R> : T extends infer O ? {
|
124 | [K in keyof O]: O[K];
|
125 | } : never;
|
126 | export type ExpandRecursively<T> = T extends (...args: infer A) => infer R ? (...args: ExpandRecursively<A>) => ExpandRecursively<R> : T extends object ? T extends infer O ? {
|
127 | [K in keyof O]: ExpandRecursively<O[K]>;
|
128 | } : never : T;
|
129 | type Identity<T> = T;
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | export type Mapped<T> = Identity<{
|
135 | [k in keyof T]: T[k];
|
136 | }>;
|
137 | export type If2<B extends Boolean2, Then, Else = never> = B extends 1 ? Then : Else;
|
138 | export type Boolean2 = 0 | 1;
|
139 | export type Key = string | number | symbol;
|
140 | export type BuiltIn = Function | Error | Date | {
|
141 | readonly [Symbol.toStringTag]: string;
|
142 | } | RegExp | Generator;
|