diff --git a/src/types.ts b/src/types.ts index cb0662fc9..d768cf50d 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 1028eba83..27bf9452d 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 diff --git a/yarn.lock b/yarn.lock index b9813d796..d1229b212 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3529,9 +3529,9 @@ has@^1.0.3: function-bind "^1.1.1" hosted-git-info@^2.1.4: - version "2.8.5" - resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.5.tgz#759cfcf2c4d156ade59b0b2dfabddc42a6b9c70c" - integrity sha512-kssjab8CvdXfcXMXVcvsXum4Hwdq9XGtRD3TteMEvEbq0LXyiNQr6AprqKqfeaDXze7SxWvRxdpwE6ku7ikLkg== + version "2.8.9" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9" + integrity sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw== html-encoding-sniffer@^1.0.2: version "1.0.2"