@@ -126,7 +126,7 @@ export function createCacheKeyComparator(equalityCheck: EqualityFn) {
126
126
/**
127
127
* @public
128
128
*/
129
- export interface DefaultMemoizeOptions {
129
+ export interface DefaultMemoizeOptions < T = any > {
130
130
/**
131
131
* Used to compare the individual arguments of the provided calculation function.
132
132
*
@@ -142,7 +142,7 @@ export interface DefaultMemoizeOptions {
142
142
* use case, where an update to another field in the original data causes a recalculation
143
143
* due to changed references, but the output is still effectively the same.
144
144
*/
145
- resultEqualityCheck ?: EqualityFn
145
+ resultEqualityCheck ?: EqualityFn < T >
146
146
/**
147
147
* The cache size for the selector. If greater than 1, the selector will use an LRU cache internally.
148
148
*
@@ -167,7 +167,7 @@ export interface DefaultMemoizeOptions {
167
167
*/
168
168
export function defaultMemoize < Func extends AnyFunction > (
169
169
func : Func ,
170
- equalityCheckOrOptions ?: EqualityFn | DefaultMemoizeOptions
170
+ equalityCheckOrOptions ?: EqualityFn | DefaultMemoizeOptions < ReturnType < Func > >
171
171
) {
172
172
const providedOptions =
173
173
typeof equalityCheckOrOptions === 'object'
@@ -191,20 +191,20 @@ export function defaultMemoize<Func extends AnyFunction>(
191
191
192
192
// we reference arguments instead of spreading them for performance reasons
193
193
function memoized ( ) {
194
- let value = cache . get ( arguments )
194
+ let value = cache . get ( arguments ) as ReturnType < Func >
195
195
if ( value === NOT_FOUND ) {
196
196
// @ts -ignore
197
- value = func . apply ( null , arguments )
197
+ value = func . apply ( null , arguments ) as ReturnType < Func >
198
198
resultsCount ++
199
199
200
200
if ( resultEqualityCheck ) {
201
201
const entries = cache . getEntries ( )
202
202
const matchingEntry = entries . find ( entry =>
203
- resultEqualityCheck ( entry . value , value )
203
+ resultEqualityCheck ( entry . value as ReturnType < Func > , value )
204
204
)
205
205
206
206
if ( matchingEntry ) {
207
- value = matchingEntry . value
207
+ value = matchingEntry . value as ReturnType < Func >
208
208
resultsCount --
209
209
}
210
210
}
0 commit comments