Merge pull request #28857 from madprog/redux-promise-middleware/dispatch-return-value

redux-promise-middleware: fix Dispatch return type
This commit is contained in:
Nathan Shively-Sanders
2018-09-25 08:52:04 -07:00
committed by GitHub
2 changed files with 18 additions and 1 deletions
+16
View File
@@ -2,7 +2,23 @@
// Project: https://github.com/pburtchaell/redux-promise-middleware
// Definitions by: ianks <https://github.com/ianks>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// TypeScript Version: 2.8
import { Middleware } from 'redux';
export default function promiseMiddleware(config?: { promiseTypeSuffixes?: string[], promiseTypeDelimiter?: string }): Middleware;
declare module "redux" {
export interface PromiseAction<R> extends Action {
payload: Promise<R>;
}
type PayloadType<PA> = PA extends PromiseAction<infer R> ? R : never;
export interface Dispatch<S> {
<R, PA extends PromiseAction<R>>(action: PA): Promise<{
value: PayloadType<PA>;
type: string;
}>;
}
}
@@ -2,7 +2,6 @@ import { createStore, applyMiddleware, Store, Dispatch } from "redux";
import promiseMiddleware from "redux-promise-middleware";
declare var rootReducer: (state: any, action: any) => any;
declare var Promise: any;
declare var doSomethingAsyncAndReturnPromise: any;
declare var someActionCreator: any;
@@ -38,6 +37,8 @@ const actionCreator2 = () => ({
promise: Promise.resolve((action: string, dispatch: Dispatch<any>, getState: Function) => {
dispatch({ type: "SECEOND_ACTION_TYPE", payload: "..." });
dispatch(someActionCreator());
dispatch({ type: "CHAINED_ACTION", payload: Promise.resolve("...") })
.then(({ type, value }) => {})
})
}
});