From de686093c804dd3b2befb0ddbb73b9c0d677a837 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Wed, 29 Nov 2023 19:03:28 -0800 Subject: [PATCH] fix(types): introduce the MapLike-type instead of using Map As of today, the https://github.com/isaacs/node-lru-cache cannot be used as a cache for memoization since `LRUCache` doesn't define the `Symbol.toStringTag`. This patch narrows down type requirements for cache implementations. --- index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index cf7be71..5316347 100644 --- a/index.ts +++ b/index.ts @@ -1,3 +1,10 @@ +type MapLike = { + set(key: K, value: V): void + get(key: K): V | undefined + has(key: K): boolean + delete(key: K): void +} + export interface MemoizeOptions { /** * Provides a single value to use as the Key for the memoization. @@ -9,7 +16,7 @@ export interface MemoizeOptions { * The Cache implementation to provide. Must be a Map or Map-alike. * Defaults to a Map. Useful for replacing the cache with an LRU cache or similar. */ - cache?: Map + cache?: MapLike } export type MemoizableFunction = (this: T, ...args: A) => R