Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export BatchEnhancer to allow custom action types #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

2 participants