Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NoQA] [TS] Memoize - Fix key typings for cache on a memoize instance #46169

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading