mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 19:51:53 +00:00
feat(redux-api-middleware): overload redux/Dispatch signature (#38175)
This commit is contained in:
+15
-2
@@ -74,13 +74,13 @@ export interface RSAARequestTypeDescriptor<State = any, Payload = any, Meta = an
|
||||
|
||||
export interface RSAASuccessTypeDescriptor<State = any, Payload = any, Meta = any> {
|
||||
type: string | symbol;
|
||||
payload?: ((action: RSAAAction, state: State, res: any) => Payload) | Payload;
|
||||
payload?: ((action: RSAAAction, state: State, res: Response) => Payload) | Payload;
|
||||
meta?: ((action: RSAAAction, state: State, res: any) => Meta) | Meta;
|
||||
}
|
||||
|
||||
export interface RSAAFailureTypeDescriptor<State = any, Payload = any, Meta = any> {
|
||||
type: string | symbol;
|
||||
payload?: ((action: RSAAAction, state: State) => Payload) | Payload;
|
||||
payload?: ((action: RSAAAction, state: State, res: Response) => Payload) | Payload;
|
||||
meta?: ((action: RSAAAction, state: State, res: any) => Meta) | Meta;
|
||||
}
|
||||
|
||||
@@ -105,4 +105,17 @@ export interface RSAAAction<State = any, Payload = any, Meta = any> {
|
||||
[RSAA]: RSAACall<State, Payload, Meta>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redux behaviour changed by middleware, so overloads here
|
||||
*/
|
||||
declare module 'redux' {
|
||||
/*
|
||||
* Overload to add api middleware support to Redux's dispatch() function.
|
||||
* Useful for react-redux or any other library which could use this type.
|
||||
*/
|
||||
interface Dispatch {
|
||||
(action: RSAAAction): Promise<any>;
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { createStore, Store } from 'redux';
|
||||
import {
|
||||
RSAA,
|
||||
isRSAA,
|
||||
@@ -134,3 +135,14 @@ import {
|
||||
types: ['REQ_TYPE', 'SUCCESS_TYPE', 'FAILURE_TYPE'];
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const store: Store = createStore(() => undefined);
|
||||
store.dispatch({
|
||||
[RSAA]: {
|
||||
endpoint: '/test/endpoint',
|
||||
method: 'GET',
|
||||
types: ['REQ_TYPE', 'SUCCESS_TYPE', 'FAILURE_TYPE'],
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user