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

Viewed 1323

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?

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

Related