Previously the type was an intersection of all methods which typescript unexpectedly narrows to a single forward action. But instead of an intersection we actually want a union to describe one of the actions instead all the actions.
This problem occurred as I used Observable<RouterActions> as the return type of an redux-observable epic.
Fixing the type caused problems on another unexpected intersection type for the action in the middleware. Fixing this one too caused typescript to be not able to narrow the argument types for the history method anymore. To help typescript here I added a switch block which handles each tuple type separately. A bit more code than before but I saw no other solution.
I also added to type guards matchLocationChangeAction and matchUpdateLocationActions which I used to match the actions and help typescript to determine the correct types. I also exported them to be able to use them in user code with @reduxjs/toolkit or redux-observable.
Previously the type was an intersection of all methods which typescript unexpectedly narrows to a single
forward
action. But instead of an intersection we actually want a union to describe one of the actions instead all the actions.This problem occurred as I used
Observable<RouterActions>
as the return type of anredux-observable
epic.Fixing the type caused problems on another unexpected intersection type for the action in the middleware. Fixing this one too caused typescript to be not able to narrow the argument types for the history method anymore. To help typescript here I added a switch block which handles each tuple type separately. A bit more code than before but I saw no other solution.
I also added to type guards
matchLocationChangeAction
andmatchUpdateLocationActions
which I used to match the actions and help typescript to determine the correct types. I also exported them to be able to use them in user code with@reduxjs/toolkit
orredux-observable
.