@@ -7,7 +7,8 @@ export type { MergeParameters } from './versionedTypes'
7
7
*
8
8
*/
9
9
10
- /** A standard selector function, which takes three generic type arguments:
10
+ /**
11
+ * A standard selector function, which takes three generic type arguments:
11
12
* @param State The first value, often a Redux root state object
12
13
* @param Result The final result returned by the selector
13
14
* @param Params All additional arguments passed into the selector
@@ -26,7 +27,7 @@ export type Selector<
26
27
: ( state : State , ...params : Params ) => Result
27
28
28
29
/** Selectors generated by Reselect have several additional fields attached: */
29
- export interface OutputSelectorFields < Combiner extends UnknownFunction , Keys > {
30
+ export interface OutputSelectorFields < Combiner extends AnyFunction , Keys > {
30
31
/** The final function passed to `createSelector` */
31
32
resultFunc : Combiner
32
33
/** The same function, memoized */
@@ -41,21 +42,23 @@ export interface OutputSelectorFields<Combiner extends UnknownFunction, Keys> {
41
42
resetRecomputations : ( ) => number
42
43
}
43
44
44
- /** Represents the actual selectors generated by `createSelector`.
45
+ /**
46
+ * Represents the actual selectors generated by `createSelector`.
45
47
* The selector is:
46
48
* - "a function that takes this state + params and returns a result"
47
49
* - plus the attached additional fields
48
50
*/
49
51
export type OutputSelector <
50
52
S extends SelectorArray ,
51
53
Result ,
52
- Combiner extends UnknownFunction ,
54
+ Combiner extends AnyFunction ,
53
55
Params extends readonly any [ ] = never , // MergeParameters<S>
54
56
Keys = { }
55
57
> = Selector < GetStateFromSelectors < S > , Result , Params > &
56
58
OutputSelectorFields < Combiner , Keys >
57
59
58
- /** A selector that is assumed to have one additional argument, such as
60
+ /**
61
+ * A selector that is assumed to have one additional argument, such as
59
62
* the props from a React component
60
63
*/
61
64
export type ParametricSelector < State , Props , Result > = Selector <
@@ -69,9 +72,10 @@ export type OutputParametricSelector<
69
72
State ,
70
73
Props ,
71
74
Result ,
72
- Combiner extends UnknownFunction ,
75
+ Combiner extends AnyFunction ,
73
76
Keys = { }
74
- > = ParametricSelector < State , Props , Result > & OutputSelectorFields < Combiner , Keys >
77
+ > = ParametricSelector < State , Props , Result > &
78
+ OutputSelectorFields < Combiner , Keys >
75
79
76
80
/** An array of input selectors */
77
81
export type SelectorArray = ReadonlyArray < Selector >
@@ -106,10 +110,37 @@ export type GetParamsFromSelectors<
106
110
*/
107
111
108
112
/** Any function with arguments */
109
- export type UnknownFunction = ( ...args : any [ ] ) => any
113
+ export type AnyFunction = ( ...args : any [ ] ) => any
114
+ /** Any function with unknown arguments */
115
+ export type UnknownFunction = ( ...args : unknown [ ] ) => unknown
116
+ /** Any Memoizer function. A memoizer is a function that accepts another function and returns it. */
117
+ export type UnknownMemoizer < Func extends UnknownFunction = UnknownFunction > = (
118
+ func : Func ,
119
+ ...options : any [ ]
120
+ ) => Func
121
+
122
+ /**
123
+ * Omit any index signatures from the given object type, leaving only explicitly defined properties.
124
+ * Source: https://stackoverflow.com/questions/51465182/how-to-remove-index-signature-using-mapped-types/68261113#68261113
125
+ * This is mainly used to remove explicit `any`s from the return type of some memoizers. e.g: `microMemoize`
126
+ */
127
+ export type OmitIndexSignature < ObjectType > = {
128
+ [ KeyType in keyof ObjectType as { } extends Record < KeyType , unknown >
129
+ ? never
130
+ : KeyType ] : ObjectType [ KeyType ]
131
+ }
132
+
133
+ /** Extracts memoize options from the parameters of a memoizer function. */
134
+ export type MemoizeOptsFromParams < MemoizeFunction extends UnknownMemoizer > =
135
+ | DropFirst < Parameters < MemoizeFunction > > [ 0 ]
136
+ | DropFirst < Parameters < MemoizeFunction > >
137
+
138
+ /** Extract the extra properties that are attached to the return value of a memoizer. e.g.: clearCache */
139
+ export type ExtractMemoizerFields < T extends UnknownMemoizer > =
140
+ OmitIndexSignature < ReturnType < T > >
110
141
111
142
/** Extract the return type from all functions as a tuple */
112
- export type ExtractReturnType < T extends readonly UnknownFunction [ ] > = {
143
+ export type ExtractReturnType < T extends readonly AnyFunction [ ] > = {
113
144
[ index in keyof T ] : T [ index ] extends T [ number ] ? ReturnType < T [ index ] > : never
114
145
}
115
146
@@ -135,7 +166,8 @@ export type Has<U, U1> = [U1] extends [U] ? 1 : 0
135
166
*
136
167
*/
137
168
138
- /** The infamous "convert a union type to an intersection type" hack
169
+ /**
170
+ * The infamous "convert a union type to an intersection type" hack
139
171
* Source: https://github.com/sindresorhus/type-fest/blob/main/source/union-to-intersection.d.ts
140
172
* Reference: https://github.com/microsoft/TypeScript/issues/29594
141
173
*/
0 commit comments