Skip to content

Commit

Permalink
Merge pull request #46169 from callstack-internal/fix/memoize-instanc…
Browse files Browse the repository at this point in the history
…e-cache-key-type
  • Loading branch information
mountiny authored Jul 25, 2024
2 parents 2dd7654 + 7d13c80 commit b1739fb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libs/memoize/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
import type {Constructor} from 'type-fest';
import type {TakeFirst} from '@src/types/utils/TupleOperations';
import ArrayCache from './cache/ArrayCache';
import {MemoizeStats} from './stats';
import type {ClientOptions, MemoizedFn, MemoizeFnPredicate, Stats} from './types';
Expand Down Expand Up @@ -42,7 +43,7 @@ class Memoize {
* @param opts - Options for the memoization layer, for more details see `ClientOptions` type.
* @returns Memoized function with a cache API attached to it.
*/
function memoize<Fn extends MemoizeFnPredicate, Key, MaxArgs extends number = Parameters<Fn>['length']>(fn: Fn, opts?: ClientOptions<Fn, MaxArgs, Key>) {
function memoize<Fn extends MemoizeFnPredicate, MaxArgs extends number = Parameters<Fn>['length'], Key = TakeFirst<Parameters<Fn>, MaxArgs>>(fn: Fn, opts?: ClientOptions<Fn, MaxArgs, Key>) {
const options = mergeOptions<Fn, MaxArgs, Key>(opts);

const cache = ArrayCache<Key, ReturnType<Fn>>({maxSize: options.maxSize, keyComparator: getEqualityComparator(options)});
Expand Down

0 comments on commit b1739fb

Please sign in to comment.