manaflair / redux-batch

Enhance your Redux store to support batched actions
174 stars 12 forks source link

Export BatchEnhancer to allow custom action types #20

Open cmfcmf opened 5 years ago

cmfcmf commented 5 years ago

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():

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():

const store = createStore(
  combineReducers<State, MyAction>(reducers),
  initialState,
  reduxBatch as BatchEnhancer<Action>
);
sperezm97 commented 4 years ago

@arcanis would you please check this ?