Skip to content

Commit

Permalink
fix global mutate generic (#1159)
Browse files Browse the repository at this point in the history
fix #1155
  • Loading branch information
promer94 committed May 9, 2021
1 parent 504306b commit a3709b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,20 @@ export type Mutator<Data = any> = (
shouldRevalidate?: boolean
) => Promise<Data | undefined>

export type ScopedMutator<Data> = (
key: Key,
data?: Data | Promise<Data> | MutatorCallback<Data>,
shouldRevalidate?: boolean
) => Promise<Data | undefined>
export interface ScopedMutator<Data = any> {
/** This is used for bound mutator */
(
key: Key,
data?: Data | Promise<Data> | MutatorCallback<Data>,
shouldRevalidate?: boolean
): Promise<Data | undefined>
/** This is used for global mutator */
<T = any>(
key: Key,
data?: T | Promise<T> | MutatorCallback<T>,
shouldRevalidate?: boolean
): Promise<T | undefined>
}

export type KeyedMutator<Data> = (
data?: Data | Promise<Data> | MutatorCallback<Data>,
Expand Down
4 changes: 2 additions & 2 deletions src/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,8 @@ Object.defineProperty(SWRConfig, 'default', {
export const mutate = internalMutate.bind(
null,
defaultConfig.cache
) as ScopedMutator<any>
) as ScopedMutator

export function createCache<Data>(
provider: Cache
): {
Expand All @@ -713,5 +714,4 @@ export function createCache<Data>(
mutate: internalMutate.bind(null, cache) as ScopedMutator<Data>
}
}

export default useSWR

0 comments on commit a3709b3

Please sign in to comment.