Skip to content

Conversation

cmfcmf
Copy link

@cmfcmf cmfcmf commented Jan 20, 2019

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>
);

@sperezm97
Copy link

@arcanis would you please check this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants