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

declare own Dispatch and Store interfaces #83

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {Middleware, Dispatch} from "redux";
import { Action, Middleware, Dispatch as ReduxDispatch, Store as ReduxStore } from "redux";


export type ThunkAction<R, S, E> = (dispatch: Dispatch<S>, getState: () => S,
extraArgument: E) => R;

declare module "redux" {
export interface Dispatch<S> {
export interface Dispatch<S> extends ReduxDispatch<S> {
<R, E>(asyncAction: ThunkAction<R, S, E>): R;
}
}

export interface Store<S> extends ReduxStore<S> {
dispatch: Dispatch<S>;
}

export type ThunkAction<R, S, E> = (dispatch: Dispatch<S>, getState: () => S,
extraArgument: E) => R;

declare const thunk: Middleware & {
withExtraArgument(extraArgument: any): Middleware;
withExtraArgument(extraArgument: any): Middleware;
};

export default thunk;
9 changes: 6 additions & 3 deletions test/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Store, Middleware} from 'redux';
import thunk, {ThunkAction} from '../index.d.ts';

import { Action, Dispatch as ReduxDispatch, Middleware } from 'redux';
import thunk, { Dispatch, ThunkAction, Store } from '../index.d.ts';

declare const store: Store<{foo: string}>;

Expand Down Expand Up @@ -31,3 +30,7 @@ const thunkAction: ThunkAction<void, {foo: string}, {bar: number}> =
const thunkActionDispatchOnly: ThunkAction<void, {}, {}> = dispatch => {
dispatch({type: 'FOO'});
};

export const otherMiddleware: Middleware = (store: Store<any>) => (next: ReduxDispatch<any>) => (action: Action) => {
next(action);
};