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

Type error with getDefaultMiddleware() #3

Open
chmac opened this issue Nov 23, 2024 · 3 comments
Open

Type error with getDefaultMiddleware() #3

chmac opened this issue Nov 23, 2024 · 3 comments

Comments

@chmac
Copy link

chmac commented Nov 23, 2024

Firstly, thanks for this library, it's great to see another option to use promises with sagas.

I'm stuck on a typing problem using getDefaultMiddleware() from redux-toolkit. This is my attempt to add the promise middleware to my store:

export const store = configureStore({
  reducer,
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware().concat(promiseMiddleware).concat(sagaMiddleware),
  devTools: !isOnDevice,
  enhancers: (getDefaultEnhancers) =>
    getDefaultEnhancers().concat(maybeDevToolsEnhancer),
});

But I get the following error:

src/redux/store.ts:30:3 - error TS2719: Type '(getDefaultMiddleware: GetDefaultMiddleware<{ relays: import("/Users/chm/Code/trustroots/nostroots/nr-app/src/redux/slices/relays.slice").RelaysState; map: MapState; events: import("/Users/chm/Code/trustroots/nostroots/nr-app/node_modules/@reduxjs/toolkit/dist/index").EntityState<import("/Users/chm/Code/trustroots/n...' is not assignable to type '(getDefaultMiddleware: GetDefaultMiddleware<{ relays: import("/Users/chm/Code/trustroots/nostroots/nr-app/src/redux/slices/relays.slice").RelaysState; map: MapState; events: import("/Users/chm/Code/trustroots/nostroots/nr-app/node_modules/@reduxjs/toolkit/dist/index").EntityState<import("/Users/chm/Code/trustroots/n...'. Two different types with this name exist, but they are unrelated.
  Type 'Tuple<[ThunkMiddleware<{ relays: RelaysState; map: MapState; events: EntityState<EventWithMetadata, string>; publish: PublishState; }, UnknownAction>, Middleware<...>, SagaMiddleware<...>]>' is not assignable to type 'Tuple<Middlewares<{ relays: RelaysState; map: MapState; events: EntityState<EventWithMetadata, string>; publish: PublishState; }>>'.
    Type '[ThunkMiddleware<{ relays: RelaysState; map: MapState; events: EntityState<EventWithMetadata, string>; publish: PublishState; }, UnknownAction>, Middleware<...>, SagaMiddleware<...>]' is not assignable to type 'Middlewares<{ relays: RelaysState; map: MapState; events: EntityState<EventWithMetadata, string>; publish: PublishState; }>'.
      Type 'ThunkMiddleware<{ relays: RelaysState; map: MapState; events: EntityState<EventWithMetadata, string>; publish: PublishState; }, UnknownAction> | Middleware<...> | SagaMiddleware<...>' is not assignable to type 'Middleware<{}, { relays: RelaysState; map: MapState; events: EntityState<EventWithMetadata, string>; publish: PublishState; }, Dispatch<...>>'.
        Type 'Middleware<{}, any, Dispatch<AnyAction>>' is not assignable to type 'Middleware<{}, { relays: RelaysState; map: MapState; events: EntityState<EventWithMetadata, string>; publish: PublishState; }, Dispatch<...>>'.
          Type '(next: Dispatch<AnyAction>) => (action: any) => any' is not assignable to type '(next: (action: unknown) => unknown) => (action: unknown) => unknown'.
            Types of parameters 'next' and 'next' are incompatible.
              Type '(action: unknown) => unknown' is not assignable to type 'Dispatch<AnyAction>'.
                Type 'unknown' is not assignable to type 'Promise<any>'.

30   middleware: (getDefaultMiddleware) =>
     ~~~~~~~~~~

Do you know how I could use this middleware with redux toolkit's configureStore()?

@chmac
Copy link
Author

chmac commented Nov 23, 2024

Having dug into this a little further, I think the issue is that we're using a newer version of redux than this package. I have the same problem with https://github.com/tomekkleszcz/redux-saga-promise-actions.

I think the issue is caused by the change from this in version 4.2.1:

https://github.com/tomekkleszcz/redux-saga-promise-actions#readme

To this in version 5.0.1:

https://github.com/reduxjs/redux/blob/9ff849ae48187e699dd0252fcc06f2b2d2470589/src/types/middleware.ts#L8-L30

@chmac
Copy link
Author

chmac commented Nov 23, 2024

Further update, if anybody else lands here with this problem, I think I managed to find a solution for pnpm by setting an override in package.json that forces redux to 5.0.1 across the whole tree like so:

  "pnpm": {
    "overrides": {
      "redux": "^5.0.1"
    }
  },

@teneko
Copy link
Owner

teneko commented Nov 26, 2024

Middleware type changed - Middleware action and next are typed as unknown
(https://github.com/reduxjs/redux/releases/tag/v5.0.0)

This is called a breaking change and they are herbely permitted to do that when jumping from 4.* to 5.*.

Did you just asked me to update my library? :O

I will probably update in the weekend. Thanks for bringing this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants