diff --git a/src/_internal/types.ts b/src/_internal/types.ts index 528dae932..85fc5dde2 100644 --- a/src/_internal/types.ts +++ b/src/_internal/types.ts @@ -509,7 +509,10 @@ export type RevalidateCallback = ( opts?: any ) => RevalidateCallbackReturnType[K] -export interface Cache { +export type Cache = Omit< + Map, + 'keys' | 'get' | 'set' | 'delete' +> & { keys(): IterableIterator get(key: string): State | undefined set(key: string, value: State): void diff --git a/test/use-swr-cache.test.tsx b/test/use-swr-cache.test.tsx index 20466383b..fd5fd9646 100644 --- a/test/use-swr-cache.test.tsx +++ b/test/use-swr-cache.test.tsx @@ -252,16 +252,24 @@ describe('useSWR - cache provider', () => { parentCache = parentCache_ return { keys: () => parentCache.keys(), - set: (k, v) => parentCache_.set(k, v), + set: (k, v) => parentCache.set(k, v), get: k => { // We append `-extended` to the value returned by the parent cache. - const v = parentCache_.get(k) + const v = parentCache.get(k) if (v && typeof v.data !== 'undefined') { return { ...v, data: v.data + '-extended' } } return v }, - delete: k => parentCache_.delete(k) + delete: k => parentCache.delete(k), + clear: () => parentCache.clear(), + size: parentCache.size, + values: parentCache.values(), + has: k => parentCache.has(k), + entries: parentCache.entries(), + forEach: k => parentCache.forEach(k), + [Symbol.iterator]: parentCache[Symbol.iterator](), + [Symbol.toStringTag]: parentCache[Symbol.toStringTag] } } })