Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redux Dynamic Modules: Type 'AnyAction' is not assignable to type 'Action'

I'm implementing redux-dynamic-modules in my application and it is not the first module in my app, but I get strange error when I try to create this module:

export const reduxProfile = () => {
  return {
    id: 'profile',
    reducerMap: {
      profile: reducer
    },
    sagas: [profileSagas],
    retained: true
  }
}
          Type 'Reducer<ProfileState, Action>' is not assignable to type 'Reducer<any, AnyAction>'.
            Types of parameters 'action' and 'action' are incompatible.
              Type 'AnyAction' is not assignable to type 'Action'.
                Type 'AnyAction' is not assignable to type 'SetPriceAction'.

And here's my SetPriceAction which seems to look just fine:

export interface SetPriceAction extends AnyAction {
  payload: Result;
  type: ActionTypes.SET_PRICE;
}
...
export type Action =
  | ...
  | SetPriceAction;

In another module is pretty much of the same shape, and everything works fine there. Can anybody help what went wrong here?

like image 757
Sergei Klinov Avatar asked Dec 05 '25 15:12

Sergei Klinov


1 Answers

A quick bypass would be to set your payload as optional.

export interface SetPriceAction extends AnyAction {
  payload?: Result;
  type: ActionTypes.SET_PRICE;
}

But I am actively looking for a long term solution requiring the payload to be defined. I'll let you know if I make any progress on the matter

like image 60
Justin Rudat Avatar answered Dec 08 '25 06:12

Justin Rudat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!