This extends the TypeScript definitions by exporting the BatchEnhancer<A extends Action = AnyAction> type. It can be used to specify the type of actions supported by your store. For example, if all your actions have a string payload, you might define a MyAction with like this:
import { Action } from "redux";
type MyAction = Action<string> & { payload: string };
Without this PR, the following code produces these typings for store.dispatch():
(action: MyAction): MyAction (correct)
(actions: AnyAction[]): AnyAction[] (incorrect)
const store = createStore(
combineReducers<State, MyAction>(reducers),
initialState,
reduxBatch
);
With this PR, you can use the BatchEnhancer type to manually specify your action type, yielding to the correct typings for store.dispatch():
(action: MyAction): MyAction (correct)
(actions: MyAction[]): MyAction[] (incorrect)
const store = createStore(
combineReducers<State, MyAction>(reducers),
initialState,
reduxBatch as BatchEnhancer<Action>
);
This extends the TypeScript definitions by exporting the
BatchEnhancer<A extends Action = AnyAction>
type. It can be used to specify the type of actions supported by your store. For example, if all your actions have astring
payload, you might define aMyAction
with like this:Without this PR, the following code produces these typings for
store.dispatch()
:(action: MyAction): MyAction
(correct)(actions: AnyAction[]): AnyAction[]
(incorrect)With this PR, you can use the
BatchEnhancer
type to manually specify your action type, yielding to the correct typings forstore.dispatch()
:(action: MyAction): MyAction
(correct)(actions: MyAction[]): MyAction[]
(incorrect)