redux: updating redux from 5.0.0 to 5.0.1 Typescript errors

I have a bunch of thunks, updating redux from 5.0.0 to 5.0.1 triggers a bunch of errprs on dispatch:

Argument of type '(dispatch: ((action: Action<"listenerMiddleware/add">) => UnsubscribeListener) & Dispatch<UnknownAction>, getState: () => { ...; }) => Promise<...>' is not assignable to parameter of type 'UnknownAction'.

reverting it back to 5.0.0 helps.

I already use @redux/toolkit, useAppState and useAppDispatch. What else could be an issue?

About this issue

  • Original URL
  • State: closed
  • Created 6 months ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

Thank you @EskiMojo14, please consider an issue resolved.

yes, you can return values from a thunk - it’s just whatever the function returns. see Type Checking Redux Thunks.

that should be inferred by the ThunkDispatch type, if everything’s working correctly

image

@JustFly1984 can’t fully explain it, but the issue is solved by adding a forced resolution to ^v5. It seems that some of your dependencies still have a dependency on redux v4 (which you can see by running yarn why redux) which seems to be messing with the types somehow.

I will also note that you have an unnecessary dependency on @types/react-redux, as react-redux has shipped its own types since v8.

if that’s a satisfactory answer/workaround, please feel free to remove my access and I’ll delete my local copy 😃

i will say - it’s odd that your dispatch has the listener middleware overload when it isn’t in your store setup 😕