Skip to content

Commit

Permalink
types: loose cache types
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Apr 20, 2022
1 parent dc78549 commit 3f308e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,5 @@ export interface Cache<Data = any> {
get(key: Key): Data | null | undefined
set(key: Key, value: Data): void
delete(key: Key): void
[key: string]: any
}
12 changes: 12 additions & 0 deletions test/type/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useSWRConfig } from 'swr'
import { expectType } from './utils'

export function useSWRLooseCache() {
const { cache } = useSWRConfig()
expectType<any>(cache.values())
}

export function useSWRMapCache() {
const cache = useSWRConfig().cache as Map<string, any>
expectType<Map<string, any>['values']>(cache.values)
}

0 comments on commit 3f308e9

Please sign in to comment.