@@ -7,7 +7,8 @@ export type { MergeParameters } from './versionedTypes'
77 *
88 */
99
10- /** A standard selector function, which takes three generic type arguments:
10+ /**
11+ * A standard selector function, which takes three generic type arguments:
1112 * @param State The first value, often a Redux root state object
1213 * @param Result The final result returned by the selector
1314 * @param Params All additional arguments passed into the selector
@@ -26,7 +27,7 @@ export type Selector<
2627 : ( state : State , ...params : Params ) => Result
2728
2829/** 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 > {
3031 /** The final function passed to `createSelector` */
3132 resultFunc : Combiner
3233 /** The same function, memoized */
@@ -41,21 +42,23 @@ export interface OutputSelectorFields<Combiner extends UnknownFunction, Keys> {
4142 resetRecomputations : ( ) => number
4243}
4344
44- /** Represents the actual selectors generated by `createSelector`.
45+ /**
46+ * Represents the actual selectors generated by `createSelector`.
4547 * The selector is:
4648 * - "a function that takes this state + params and returns a result"
4749 * - plus the attached additional fields
4850 */
4951export type OutputSelector <
5052 S extends SelectorArray ,
5153 Result ,
52- Combiner extends UnknownFunction ,
54+ Combiner extends AnyFunction ,
5355 Params extends readonly any [ ] = never , // MergeParameters<S>
5456 Keys = { }
5557> = Selector < GetStateFromSelectors < S > , Result , Params > &
5658 OutputSelectorFields < Combiner , Keys >
5759
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
5962 * the props from a React component
6063 */
6164export type ParametricSelector < State , Props , Result > = Selector <
@@ -69,9 +72,10 @@ export type OutputParametricSelector<
6972 State ,
7073 Props ,
7174 Result ,
72- Combiner extends UnknownFunction ,
75+ Combiner extends AnyFunction ,
7376 Keys = { }
74- > = ParametricSelector < State , Props , Result > & OutputSelectorFields < Combiner , Keys >
77+ > = ParametricSelector < State , Props , Result > &
78+ OutputSelectorFields < Combiner , Keys >
7579
7680/** An array of input selectors */
7781export type SelectorArray = ReadonlyArray < Selector >
@@ -106,10 +110,37 @@ export type GetParamsFromSelectors<
106110 */
107111
108112/** 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 > >
110141
111142/** 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 [ ] > = {
113144 [ index in keyof T ] : T [ index ] extends T [ number ] ? ReturnType < T [ index ] > : never
114145}
115146
@@ -135,7 +166,8 @@ export type Has<U, U1> = [U1] extends [U] ? 1 : 0
135166 *
136167 */
137168
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
139171 * Source: https://github.com/sindresorhus/type-fest/blob/main/source/union-to-intersection.d.ts
140172 * Reference: https://github.com/microsoft/TypeScript/issues/29594
141173 */
0 commit comments