mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 Merge PR #45635 Add support for Promises in redux-api-middleware by @AdamCLarsen
* Add support for Promises in redux-api-middleware fix * Change promises result type def in redux-api-middleware Reducing the duplication in the type definitions for the Promises return types in functions. Change promises result type def in redux-api-middleware
This commit is contained in:
parent
dedd90e20c
commit
5ca1e873b7
14
types/redux-api-middleware/index.d.ts
vendored
14
types/redux-api-middleware/index.d.ts
vendored
@ -9,7 +9,7 @@
|
||||
|
||||
import { Dispatch, Middleware, MiddlewareAPI } from 'redux';
|
||||
|
||||
type TypeOrResolver<Arg, Type> = Type | ((arg: Arg) => Type);
|
||||
type TypeOrResolver<Arg, Type> = Type | ((arg: Arg) => Type | Promise<Type>);
|
||||
|
||||
/**
|
||||
* This module is also a UMD module that exposes a global variable 'ReduxApiMiddleware'
|
||||
@ -64,20 +64,20 @@ export function createMiddleware(options?: CreateMiddlewareOptions): Middleware;
|
||||
|
||||
export interface RSAARequestTypeDescriptor<State = any, Payload = any, Meta = any> {
|
||||
type: string | symbol;
|
||||
payload?: ((action: RSAAAction, state: State) => Payload) | Payload;
|
||||
meta?: ((action: RSAAAction, state: State) => Meta) | Meta;
|
||||
payload?: ((action: RSAAAction, state: State) => Payload | Promise<Payload>) | Payload;
|
||||
meta?: ((action: RSAAAction, state: State) => Meta | Promise<Meta>) | Meta;
|
||||
}
|
||||
|
||||
export interface RSAASuccessTypeDescriptor<State = any, Payload = any, Meta = any> {
|
||||
type: string | symbol;
|
||||
payload?: ((action: RSAAAction, state: State, res: Response) => Payload) | Payload;
|
||||
meta?: ((action: RSAAAction, state: State, res: Response) => Meta) | Meta;
|
||||
payload?: ((action: RSAAAction, state: State, res: Response) => Payload | Promise<Payload>) | Payload;
|
||||
meta?: ((action: RSAAAction, state: State, res: Response) => Meta | Promise<Meta>) | Meta;
|
||||
}
|
||||
|
||||
export interface RSAAFailureTypeDescriptor<State = any, Payload = any, Meta = any> {
|
||||
type: string | symbol;
|
||||
payload?: ((action: RSAAAction, state: State, res: Response) => Payload) | Payload;
|
||||
meta?: ((action: RSAAAction, state: State, res: Response) => Meta) | Meta;
|
||||
payload?: ((action: RSAAAction, state: State, res: Response) => Payload | Promise<Payload>) | Payload;
|
||||
meta?: ((action: RSAAAction, state: State, res: Response) => Meta | Promise<Meta>) | Meta;
|
||||
}
|
||||
|
||||
export type RSAARequestType<State = any, Payload = any, Meta = any> =
|
||||
|
||||
@ -145,6 +145,26 @@ import {
|
||||
types: ['REQ_TYPE', 'SUCCESS_TYPE', 'FAILURE_TYPE'];
|
||||
}
|
||||
|
||||
class PromiseStateDrivenRSAACall implements RSAACall<State> {
|
||||
endpoint(state: State) {
|
||||
return Promise.resolve(state.path);
|
||||
}
|
||||
headers(state: State) {
|
||||
return Promise.resolve(state.headers);
|
||||
}
|
||||
options(state: State) {
|
||||
return Promise.resolve(state.options);
|
||||
}
|
||||
body(state: State) {
|
||||
return Promise.resolve(state.body);
|
||||
}
|
||||
bailout(state: State) {
|
||||
return Promise.resolve(state.bailout);
|
||||
}
|
||||
method: 'GET';
|
||||
types: ['REQ_TYPE', 'SUCCESS_TYPE', 'FAILURE_TYPE'];
|
||||
}
|
||||
|
||||
class NonStateDrivenRSAACall implements RSAACall<State> {
|
||||
endpoint: '/test/endpoint';
|
||||
method: 'GET';
|
||||
@ -199,6 +219,11 @@ import {
|
||||
payload: '', // $ExpectError
|
||||
meta: (action: RSAAAction, state: number) => '', // $ExpectError
|
||||
};
|
||||
const requestDescriptor3: RSAARequestTypeDescriptor<number, number, number> = {
|
||||
type: Symbol(),
|
||||
payload: (action: RSAAAction, state: number) => Promise.resolve(state),
|
||||
meta: (action: RSAAAction, state: number) => Promise.resolve(state),
|
||||
};
|
||||
|
||||
const successDescriptor0: RSAASuccessTypeDescriptor<number, number, number> = {
|
||||
type: '',
|
||||
@ -215,6 +240,11 @@ import {
|
||||
payload: '', // $ExpectError
|
||||
meta: (action: RSAAAction, state: number) => '', // $ExpectError
|
||||
};
|
||||
const successDescriptor3: RSAASuccessTypeDescriptor<number, number, number> = {
|
||||
type: Symbol(),
|
||||
payload: (action: RSAAAction, state: number, res: Response) => Promise.resolve(state),
|
||||
meta: (action: RSAAAction, state: number, res: Response) => Promise.resolve(state),
|
||||
};
|
||||
|
||||
const failureDescriptor0: RSAAFailureTypeDescriptor<number, number, number> = {
|
||||
type: '',
|
||||
@ -231,6 +261,11 @@ import {
|
||||
payload: '', // $ExpectError
|
||||
meta: (action: RSAAAction, state: number) => '', // $ExpectError
|
||||
};
|
||||
const failureDescriptor3: RSAAFailureTypeDescriptor<number, number, number> = {
|
||||
type: Symbol(),
|
||||
payload: (action: RSAAAction, state: number, res: Response) => Promise.resolve(state),
|
||||
meta: (action: RSAAAction, state: number, res: Response) => Promise.resolve(state),
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user