diff --git a/src/types.ts b/src/types.ts index c49301f3c..072df0772 100644 --- a/src/types.ts +++ b/src/types.ts @@ -90,11 +90,20 @@ export type Mutator = ( shouldRevalidate?: boolean ) => Promise -export type ScopedMutator = ( - key: Key, - data?: Data | Promise | MutatorCallback, - shouldRevalidate?: boolean -) => Promise +export interface ScopedMutator { + /** This is used for bound mutator */ + ( + key: Key, + data?: Data | Promise | MutatorCallback, + shouldRevalidate?: boolean + ): Promise + /** This is used for global mutator */ + ( + key: Key, + data?: T | Promise | MutatorCallback, + shouldRevalidate?: boolean + ): Promise +} export type KeyedMutator = ( data?: Data | Promise | MutatorCallback, diff --git a/src/use-swr.ts b/src/use-swr.ts index 35fd4a68e..70ba71fa3 100644 --- a/src/use-swr.ts +++ b/src/use-swr.ts @@ -700,7 +700,8 @@ Object.defineProperty(SWRConfig, 'default', { export const mutate = internalMutate.bind( null, defaultConfig.cache -) as ScopedMutator +) as ScopedMutator + export function createCache( provider: Cache ): { @@ -713,5 +714,4 @@ export function createCache( mutate: internalMutate.bind(null, cache) as ScopedMutator } } - export default useSWR