DefinitelyTyped/types/redux-promise-middleware/index.d.ts
Paul Morelle 0e7cc3ff0c redux-promise-middleware: fix Dispatch return type
When the payload is a Promise, the Promise Middleware will change what
`dispatch()` returns. Reflect this with typing.
According to documentation [1], it is a Promise of an object with the
promised `value` and the FULFILLED action `type`.

[1] https://github.com/pburtchaell/redux-promise-middleware/blob/master/docs/guides/chaining-actions.md
2018-09-13 12:00:44 -04:00

25 lines
767 B
TypeScript

// Type definitions for redux-promise-middleware
// 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;
}>;
}
}