diff --git a/README.md b/README.md index 6670e72..ab2020f 100644 --- a/README.md +++ b/README.md @@ -133,13 +133,10 @@ function fetchUser(id) { } ``` -If you're setting up the store by hand, the default `thunk` export has an attached `thunk.withExtraArgument()` function that should be used to generate the correct thunk middleware: +If you're setting up the store by hand, the named export `withExtraArgument()` function should be used to generate the correct thunk middleware: ```js -const store = createStore( - reducer, - applyMiddleware(thunk.withExtraArgument(api)) -) +const store = createStore(reducer, applyMiddleware(withExtraArgument(api))) ``` ## Why Do I Need This? diff --git a/src/index.ts b/src/index.ts index d7f762e..58bab3d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,15 +36,7 @@ function createThunkMiddleware< return middleware } -export const thunk = createThunkMiddleware() as ThunkMiddleware & { - withExtraArgument< - ExtraThunkArg, - State = any, - BasicAction extends Action = AnyAction - >( - extraArgument: ExtraThunkArg - ): ThunkMiddleware -} +export const thunk = createThunkMiddleware() // Export the factory function so users can create a customized version // with whatever "extra arg" they want to inject into their thunks diff --git a/src/types.ts b/src/types.ts index 091f760..973e4ac 100644 --- a/src/types.ts +++ b/src/types.ts @@ -78,7 +78,7 @@ export type ThunkActionDispatch< * @template State The redux state * @template BasicAction The (non-thunk) actions that can be dispatched * @template ExtraThunkArg An optional extra argument to pass to a thunk's - * inner function. (Only used if you call `thunk.withExtraArgument()`) + * inner function. (Only used if you call `withExtraArgument()`) */ export type ThunkMiddleware< State = any, diff --git a/typescript_test/typescript.ts b/typescript_test/typescript.ts index 9d37f87..2d22337 100644 --- a/typescript_test/typescript.ts +++ b/typescript_test/typescript.ts @@ -2,7 +2,7 @@ import { applyMiddleware, bindActionCreators, createStore } from 'redux' import type { Action, AnyAction } from 'redux' -import { thunk } from '../src/index' +import { thunk, withExtraArgument } from '../src/index' import type { ThunkAction, ThunkActionDispatch, @@ -70,7 +70,7 @@ store.dispatch(testGetState()) const storeThunkArg = createStore( fakeReducer, applyMiddleware( - thunk.withExtraArgument('bar') as ThunkMiddleware + withExtraArgument('bar') as ThunkMiddleware ) ) storeThunkArg.dispatch({ type: 'FOO' })