I have a thunked store created like
export const store = createStore<IState, IAction<string, any>, {}, {}>(combinedReducers, applyMiddleware(thunk));
I want to dispatch a thunked action outside of a React component, like store.dispatch(myThunkedActionCreator(data));
However, the type of dispatch
is coming in as Dispatch<IAction<string, any>>
instead of ThunkDispatch<State, void, ActionType>
, which would be the type necessary to pass a thunk to the store's modified dispatch. I import the store as import { store } from '../Store/Store';
How can I get store.dispatch
to have the right, thunked dispatch type?
I know I can typecast dispatch
at its callsites, but that's a hack. I'm not currently using RTK, which solves the typing problem, but that's out of scope for me at the moment.