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); }