mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
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
25 lines
767 B
TypeScript
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;
|
|
}>;
|
|
}
|
|
}
|