Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 14, 2023
1 parent 7650653 commit 9f7869d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.ts
Expand Up @@ -104,10 +104,14 @@ export default function mem<
maxAge,
}: Options<FunctionToMemoize, CacheKeyType> = {},
): FunctionToMemoize {
if (typeof maxAge === 'number' && maxAge <= 0) {
if (maxAge === 0) {
return fn;
}

if (typeof maxAge === 'number' && maxAge < 0) {
throw new TypeError('The `maxAge` option should not be a negative number.');
}

const memoized = function (this: any, ...arguments_: Parameters<FunctionToMemoize>): ReturnType<FunctionToMemoize> {
const key = cacheKey ? cacheKey(arguments_) : arguments_[0] as CacheKeyType;

Expand All @@ -131,7 +135,7 @@ export default function mem<
timer.unref?.();

const timers = cacheTimerStore.get(fn) ?? new Set<number>();
timers.add(timer as number);
timers.add(timer as unknown as number);
cacheTimerStore.set(fn, timers);
}

Expand Down

0 comments on commit 9f7869d

Please sign in to comment.