Skip to content

Calling dispatch with a thunk from createAsyncAppThunk causes a Typescript error #4312

Answered by EskiMojo14
renchap asked this question in Q&A
Discussion options

You must be logged in to vote

the issue is with your other middleware types - they should all be Middleware<{}, RootState>. using Record<string, never> is causing the issue, just disable the lint rule for those lines.
same goes for the loadingBarMiddleware, it doesn't add any overloads to dispatch so should just be {} for the DispatchExt.

The first type parameter is for adding overloads to dispatch, for example if you had a middleware that intercepted dispatched promises:

const boxPromiseResultMiddleware: Middleware<
  <T>(promise: Promise<T>) => Promise<{ value: T }>
> = (api) => (next) => (action) => {
  if (action instanceof Promise) {
    return action.then((value) => ({ value }));
  }
  return next(action);
};

c…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@EskiMojo14
Comment options

@renchap
Comment options

@aryaemami59
Comment options

@phryneas
Comment options

@EskiMojo14
Comment options

Answer selected by renchap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants