From 9f7869d882e385046a2a540e2dd5fa9b3b620f95 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 14 Nov 2023 21:50:45 +0700 Subject: [PATCH] tweaks --- index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index feb2abe..4f35c76 100644 --- a/index.ts +++ b/index.ts @@ -104,10 +104,14 @@ export default function mem< maxAge, }: Options = {}, ): 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): ReturnType { const key = cacheKey ? cacheKey(arguments_) : arguments_[0] as CacheKeyType; @@ -131,7 +135,7 @@ export default function mem< timer.unref?.(); const timers = cacheTimerStore.get(fn) ?? new Set(); - timers.add(timer as number); + timers.add(timer as unknown as number); cacheTimerStore.set(fn, timers); }