Closed
Description
When creating a listener middleware that matches an action using matcher: isAnyOf(...)
it's no longer getting the correct action type. In this instance it's missing that it's a payload action.
Here's a code example:
const notificationSlice = createSlice({
name: 'notification',
initialState,
reducers: {
addNotification: {
reducer: (state, { payload: { notificationType, notification, autoDismissInMs, id } }: PayloadAction<FullNotificationActionPayload>) => {
state[notificationType].push({ notification, autoDismissInMs, id });
},
prepare: (payload: NotificationActionPayload) => ({ payload: { ...payload, id: nanoid() } })
},
}
})
export const { addNotification } = notificationSlice.actions;
And where I create my listenerMiddleware:
notificationEffects.startListening({
matcher: isAnyOf(addNotification),
effect: async (action, listenerApi) => {
const { autoDismissInMs, notificationType, id } = action.payload;
.
.
.
Here it will complain that action.payload does not exist since action is typed as Action instead of PayloadAction.
This is not a big issue in this example since I shoud probably just use actionCreateor
as a matcher instead, then action get's the correct type.
But the same listener middleware has another listner where I match multiple actions like this:
notificationEffects.startListening({
matcher: isAnyOf(addSuccess, addNotice, addError),
effect: async (action, listenerApi) => {
listenerApi.dispatch(addNotification(action.payload));
},
});
The same problem here.
This worked prior to upgrading to the beta.
Metadata
Metadata
Assignees
Labels
No labels