mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
Merge pull request #28857 from madprog/redux-promise-middleware/dispatch-return-value
redux-promise-middleware: fix Dispatch return type
This commit is contained in:
+16
@@ -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 }) => {})
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user