From 763c473ac4ee484cc72fde65cb6ed2ae7ab8301e Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 20 Apr 2022 13:01:58 +0200 Subject: [PATCH] Add missing clear method to Cache type definition The Cache has been exposed since [1], which supposedly includes a .clear() method [2], which in turn is not actually present in the type definition [3]. This adds it to the type definition to align with the implementation. Since Map also contains a .clear() method [4], this shouldn't break the ability to pass that in as a map. [1] https://github.com/vercel/swr/pull/231 [2] https://github.com/vercel/swr/issues/161#issuecomment-695417107 [3] https://github.com/vercel/swr/issues/161#issuecomment-1079198998 [4] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear --- src/types.ts | 1 + test/use-swr-cache.test.tsx | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 0dea512cd..d7ef23dd4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -264,4 +264,5 @@ export interface Cache { get(key: Key): Data | null | undefined set(key: Key, value: Data): void delete(key: Key): void + clear(): void } diff --git a/test/use-swr-cache.test.tsx b/test/use-swr-cache.test.tsx index 23c4208e6..c2dd65416 100644 --- a/test/use-swr-cache.test.tsx +++ b/test/use-swr-cache.test.tsx @@ -260,7 +260,8 @@ describe('useSWR - cache provider', () => { } return v }, - delete: k => parentCache_.delete(k) + delete: k => parentCache_.delete(k), + clear: () => parentCache_.clear() } } })