Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MiddlewareArray.prepend/concat methods don't handle array arguments correctly #2432

Closed
markerikson opened this issue Jun 21, 2022 · 1 comment
Labels
bug Something isn't working TypeScript

Comments

@markerikson
Copy link
Collaborator

Per example at reduxjs/redux-thunk#333 (comment) and https://codesandbox.io/s/react-redux-toolkit-wbzkgc?file=/src/store/index.ts , it looks like gDM().prepend([someMiddleware]) doesn't handle type extraction right and the store falls back to Dispatch<AnyAction>:

const store = configureStore({
  reducer: {
    UserReducer: UserReducer,
    // // Uncomment me and get type error in file "./src/hooks/index.tsx"
    [APISlice.reducerPath]: APISlice.reducer
  },
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware()
      .prepend([UserAPIListenerMiddleware.middleware])
      .concat([APISlice.middleware])
});

I suppose we either ought to reject arrays entirely at runtime, or modify the types to deal with that.

@markerikson markerikson added bug Something isn't working TypeScript labels Jun 21, 2022
@markerikson
Copy link
Collaborator Author

I take it back. We do have typetests for this, but you do need to mark the array as const, and I can see that the resulting dispatch type is right (and that if I remove as const it fails).

Gonna close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working TypeScript
Projects
None yet
Development

No branches or pull requests

1 participant