From 3f308e9536e48a59df11c5fba241acfcbd4fe63b Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 20 Apr 2022 13:40:49 +0200 Subject: [PATCH] types: loose cache types --- src/types.ts | 1 + test/type/cache.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 test/type/cache.ts diff --git a/src/types.ts b/src/types.ts index 0dea512cd..0f7fad185 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 + [key: string]: any } diff --git a/test/type/cache.ts b/test/type/cache.ts new file mode 100644 index 000000000..46292aaa1 --- /dev/null +++ b/test/type/cache.ts @@ -0,0 +1,12 @@ +import { useSWRConfig } from 'swr' +import { expectType } from './utils' + +export function useSWRLooseCache() { + const { cache } = useSWRConfig() + expectType(cache.values()) +} + +export function useSWRMapCache() { + const cache = useSWRConfig().cache as Map + expectType['values']>(cache.values) +}