Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions test/typescript/dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const dispatchResult: Action = dispatch({type: 'TYPE'});

// thunk
declare module "../../" {
export interface Dispatch<S> {
<R>(asyncAction: (dispatch: Dispatch<S>, getState: () => S) => R): R;
export interface Dispatch<D = Action> {
<R>(asyncAction: (dispatch: Dispatch<D>, getState: () => any) => R): R;
}
}

Expand Down
16 changes: 8 additions & 8 deletions test/typescript/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import {
} from "../../"

declare module "../../" {
export interface Dispatch<S> {
<R>(asyncAction: (dispatch: Dispatch<S>, getState: () => S) => R): R;
export interface Dispatch<D = Action> {
<R>(asyncAction: (dispatch: Dispatch<D>, getState: () => any) => R): R;
}
}

type Thunk<S, O> = (dispatch: Dispatch<S>, getState?: () => S) => O;
type Thunk<S, O> = (dispatch: Dispatch, getState?: () => S) => O;

const thunkMiddleware: Middleware =
<S>({dispatch, getState}: MiddlewareAPI<S>) =>
(next: Dispatch<S>) =>
<A extends Action, B>(action: A | Thunk<S, B>): B|Action =>
<S, A extends Action>({dispatch, getState}: MiddlewareAPI<S>) =>
(next: Dispatch<A>) =>
<B>(action: A | Thunk<S, B>): B|Action =>
typeof action === 'function' ?
(<Thunk<S, B>>action)(dispatch, getState) :
next(<A>action)


const loggerMiddleware: Middleware =
<S>({getState}: MiddlewareAPI<S>) =>
(next: Dispatch<S>) =>
(next: Dispatch) =>
(action: any): any => {
console.log('will dispatch', action)

Expand Down Expand Up @@ -51,7 +51,7 @@ const storeWithThunkMiddleware = createStore(
);

storeWithThunkMiddleware.dispatch(
(dispatch: Dispatch<State>, getState: () => State) => {
(dispatch: Dispatch, getState: () => State) => {
const todos: string[] = getState().todos;
dispatch({type: 'ADD_TODO'})
}
Expand Down