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