Skip to content

Commit

Permalink
Move up the type assertion
Browse files Browse the repository at this point in the history
Now there's no need to ignore the withExtraArgument line.
  • Loading branch information
timdorr committed Oct 25, 2021
1 parent 7fb5a23 commit 014936e
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,18 @@ function createThunkMiddleware<
return middleware
}

/** The standard thunk middleware, with no extra argument included */
const thunk = createThunkMiddleware()
const thunk = createThunkMiddleware() as ThunkMiddleware & {
withExtraArgument<
ExtraThunkArg,
State = any,
BasicAction extends Action<any> = AnyAction
>(
extraArgument: ExtraThunkArg
): ThunkMiddleware<State, BasicAction, ExtraThunkArg>
}

// Attach the factory function so users can create a customized version
// with whatever "extra arg" they want to inject into their thunks
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
thunk.withExtraArgument = createThunkMiddleware

// Convince TS that the default export has the right type for `withExtraArgument`
export default thunk as typeof thunk &
ThunkMiddleware & {
withExtraArgument<
ExtraThunkArg,
State = any,
BasicAction extends Action<any> = AnyAction
>(
extraArgument: ExtraThunkArg
): ThunkMiddleware<State, BasicAction, ExtraThunkArg>
}
export default thunk

0 comments on commit 014936e

Please sign in to comment.