Skip to content

Updated the definition of 'Reducer' and 'Dispatch' for TypeScript 2.3+ #2479

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface Action {
*
* @template S State object type.
*/
export type Reducer<S> = <A extends Action>(state: S | undefined, action: A) => S;
export type Reducer<S, A extends Action = Action> = (state: S | undefined, action: A) => S;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should conform with #2467


/**
* Object whose values correspond to different reducer functions.
Expand Down Expand Up @@ -93,8 +93,8 @@ export function combineReducers<S>(reducers: ReducersMapObject<S>): Reducer<S>;
* transform, delay, ignore, or otherwise interpret actions or async actions
* before passing them to the next middleware.
*/
export interface Dispatch<S> {
<A extends Action>(action: A): A;
export interface Dispatch<TInput = Action, TReturn = Action> {
(input: TInput): TReturn;
}

/**
Expand Down Expand Up @@ -138,7 +138,7 @@ export interface Store<S> {
* Note that, if you use a custom middleware, it may wrap `dispatch()` to
* return something else (for example, a Promise you can await).
*/
dispatch: Dispatch<S>;
dispatch: Dispatch;

/**
* Reads the state tree managed by the store.
Expand Down Expand Up @@ -254,7 +254,7 @@ export const createStore: StoreCreator;
/* middleware */

export interface MiddlewareAPI<S> {
dispatch: Dispatch<S>;
dispatch: Dispatch;
getState(): S;
}

Expand All @@ -267,8 +267,8 @@ export interface MiddlewareAPI<S> {
* logging actions, performing side effects like routing, or turning an
* asynchronous API call into a series of synchronous actions.
*/
export interface Middleware {
<S>(api: MiddlewareAPI<S>): (next: Dispatch<S>) => Dispatch<S>;
export interface Middleware<S> {
(api: MiddlewareAPI<S>): (next: Dispatch) => Dispatch;
}

/**
Expand Down Expand Up @@ -340,19 +340,19 @@ export interface ActionCreatorsMapObject {
* creator wrapped into the `dispatch` call. If you passed a function as
* `actionCreator`, the return value will also be a single function.
*/
export function bindActionCreators<A extends ActionCreator<any>>(actionCreator: A, dispatch: Dispatch<any>): A;
export function bindActionCreators<A extends ActionCreator<any>>(actionCreator: A, dispatch: Dispatch): A;

export function bindActionCreators<
A extends ActionCreator<any>,
B extends ActionCreator<any>
>(actionCreator: A, dispatch: Dispatch<any>): B;
>(actionCreator: A, dispatch: Dispatch): B;

export function bindActionCreators<M extends ActionCreatorsMapObject>(actionCreators: M, dispatch: Dispatch<any>): M;
export function bindActionCreators<M extends ActionCreatorsMapObject>(actionCreators: M, dispatch: Dispatch): M;

export function bindActionCreators<
M extends ActionCreatorsMapObject,
N extends ActionCreatorsMapObject
>(actionCreators: M, dispatch: Dispatch<any>): N;
>(actionCreators: M, dispatch: Dispatch): N;


/* compose */
Expand Down