1 | import type { Dispatch, AnyAction } from 'redux';
|
2 | import type { ActionCreatorWithPreparedPayload } from './createAction';
|
3 | import type { ThunkDispatch } from 'redux-thunk';
|
4 | import type { FallbackIfUnknown, IsAny, IsUnknown } from './tsHelpers';
|
5 | export declare type BaseThunkAPI<S, E, D extends Dispatch = Dispatch, RejectedValue = undefined, RejectedMeta = unknown, FulfilledMeta = unknown> = {
|
6 | dispatch: D;
|
7 | getState: () => S;
|
8 | extra: E;
|
9 | requestId: string;
|
10 | signal: AbortSignal;
|
11 | rejectWithValue: IsUnknown<RejectedMeta, (value: RejectedValue) => RejectWithValue<RejectedValue, RejectedMeta>, (value: RejectedValue, meta: RejectedMeta) => RejectWithValue<RejectedValue, RejectedMeta>>;
|
12 | fulfillWithValue: IsUnknown<FulfilledMeta, <FulfilledValue>(value: FulfilledValue) => FulfillWithMeta<FulfilledValue, FulfilledMeta>, <FulfilledValue>(value: FulfilledValue, meta: FulfilledMeta) => FulfillWithMeta<FulfilledValue, FulfilledMeta>>;
|
13 | };
|
14 |
|
15 |
|
16 |
|
17 | export interface SerializedError {
|
18 | name?: string;
|
19 | message?: string;
|
20 | stack?: string;
|
21 | code?: string;
|
22 | }
|
23 | declare class RejectWithValue<Payload, RejectedMeta> {
|
24 | readonly payload: Payload;
|
25 | readonly meta: RejectedMeta;
|
26 | private readonly _type;
|
27 | constructor(payload: Payload, meta: RejectedMeta);
|
28 | }
|
29 | declare class FulfillWithMeta<Payload, FulfilledMeta> {
|
30 | readonly payload: Payload;
|
31 | readonly meta: FulfilledMeta;
|
32 | private readonly _type;
|
33 | constructor(payload: Payload, meta: FulfilledMeta);
|
34 | }
|
35 | /**
|
36 | * Serializes an error into a plain object.
|
37 | * Reworked from https://github.com/sindresorhus/serialize-error
|
38 | *
|
39 | * @public
|
40 | */
|
41 | export declare const miniSerializeError: (value: any) => SerializedError;
|
42 | declare type AsyncThunkConfig = {
|
43 | state?: unknown;
|
44 | dispatch?: Dispatch;
|
45 | extra?: unknown;
|
46 | rejectValue?: unknown;
|
47 | serializedErrorType?: unknown;
|
48 | pendingMeta?: unknown;
|
49 | fulfilledMeta?: unknown;
|
50 | rejectedMeta?: unknown;
|
51 | };
|
52 | declare type GetState<ThunkApiConfig> = ThunkApiConfig extends {
|
53 | state: infer State;
|
54 | } ? State : unknown;
|
55 | declare type GetExtra<ThunkApiConfig> = ThunkApiConfig extends {
|
56 | extra: infer Extra;
|
57 | } ? Extra : unknown;
|
58 | declare type GetDispatch<ThunkApiConfig> = ThunkApiConfig extends {
|
59 | dispatch: infer Dispatch;
|
60 | } ? FallbackIfUnknown<Dispatch, ThunkDispatch<GetState<ThunkApiConfig>, GetExtra<ThunkApiConfig>, AnyAction>> : ThunkDispatch<GetState<ThunkApiConfig>, GetExtra<ThunkApiConfig>, AnyAction>;
|
61 | declare type GetThunkAPI<ThunkApiConfig> = BaseThunkAPI<GetState<ThunkApiConfig>, GetExtra<ThunkApiConfig>, GetDispatch<ThunkApiConfig>, GetRejectValue<ThunkApiConfig>, GetRejectedMeta<ThunkApiConfig>, GetFulfilledMeta<ThunkApiConfig>>;
|
62 | declare type GetRejectValue<ThunkApiConfig> = ThunkApiConfig extends {
|
63 | rejectValue: infer RejectValue;
|
64 | } ? RejectValue : unknown;
|
65 | declare type GetPendingMeta<ThunkApiConfig> = ThunkApiConfig extends {
|
66 | pendingMeta: infer PendingMeta;
|
67 | } ? PendingMeta : unknown;
|
68 | declare type GetFulfilledMeta<ThunkApiConfig> = ThunkApiConfig extends {
|
69 | fulfilledMeta: infer FulfilledMeta;
|
70 | } ? FulfilledMeta : unknown;
|
71 | declare type GetRejectedMeta<ThunkApiConfig> = ThunkApiConfig extends {
|
72 | rejectedMeta: infer RejectedMeta;
|
73 | } ? RejectedMeta : unknown;
|
74 | declare type GetSerializedErrorType<ThunkApiConfig> = ThunkApiConfig extends {
|
75 | serializedErrorType: infer GetSerializedErrorType;
|
76 | } ? GetSerializedErrorType : SerializedError;
|
77 | declare type MaybePromise<T> = T | Promise<T> | (T extends any ? Promise<T> : never);
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | export declare type AsyncThunkPayloadCreatorReturnValue<Returned, ThunkApiConfig extends AsyncThunkConfig> = MaybePromise<IsUnknown<GetFulfilledMeta<ThunkApiConfig>, Returned, FulfillWithMeta<Returned, GetFulfilledMeta<ThunkApiConfig>>> | RejectWithValue<GetRejectValue<ThunkApiConfig>, GetRejectedMeta<ThunkApiConfig>>>;
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | export declare type AsyncThunkPayloadCreator<Returned, ThunkArg = void, ThunkApiConfig extends AsyncThunkConfig = {}> = (arg: ThunkArg, thunkAPI: GetThunkAPI<ThunkApiConfig>) => AsyncThunkPayloadCreatorReturnValue<Returned, ThunkApiConfig>;
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | export declare type AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig extends AsyncThunkConfig> = (dispatch: GetDispatch<ThunkApiConfig>, getState: () => GetState<ThunkApiConfig>, extra: GetExtra<ThunkApiConfig>) => Promise<ReturnType<AsyncThunkFulfilledActionCreator<Returned, ThunkArg>> | ReturnType<AsyncThunkRejectedActionCreator<ThunkArg, ThunkApiConfig>>> & {
|
102 | abort: (reason?: string) => void;
|
103 | requestId: string;
|
104 | arg: ThunkArg;
|
105 | unwrap: () => Promise<Returned>;
|
106 | };
|
107 | declare type AsyncThunkActionCreator<Returned, ThunkArg, ThunkApiConfig extends AsyncThunkConfig> = IsAny<ThunkArg, (arg: ThunkArg) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig>, unknown extends ThunkArg ? (arg: ThunkArg) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig> : [ThunkArg] extends [void] | [undefined] ? () => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig> : [void] extends [ThunkArg] ? (arg?: ThunkArg) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig> : [undefined] extends [ThunkArg] ? WithStrictNullChecks<(arg?: ThunkArg) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig>, (arg: ThunkArg) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig>> : (arg: ThunkArg) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig>>;
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | export declare type AsyncThunkOptions<ThunkArg = void, ThunkApiConfig extends AsyncThunkConfig = {}> = {
|
114 | |
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 | condition?(arg: ThunkArg, api: Pick<GetThunkAPI<ThunkApiConfig>, 'getState' | 'extra'>): MaybePromise<boolean | undefined>;
|
121 | |
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | dispatchConditionRejection?: boolean;
|
129 | serializeError?: (x: unknown) => GetSerializedErrorType<ThunkApiConfig>;
|
130 | |
131 |
|
132 |
|
133 |
|
134 |
|
135 | idGenerator?: (arg: ThunkArg) => string;
|
136 | } & IsUnknown<GetPendingMeta<ThunkApiConfig>, {
|
137 | |
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | getPendingMeta?(base: {
|
144 | arg: ThunkArg;
|
145 | requestId: string;
|
146 | }, api: Pick<GetThunkAPI<ThunkApiConfig>, 'getState' | 'extra'>): GetPendingMeta<ThunkApiConfig>;
|
147 | }, {
|
148 | |
149 |
|
150 |
|
151 | getPendingMeta(base: {
|
152 | arg: ThunkArg;
|
153 | requestId: string;
|
154 | }, api: Pick<GetThunkAPI<ThunkApiConfig>, 'getState' | 'extra'>): GetPendingMeta<ThunkApiConfig>;
|
155 | }>;
|
156 | export declare type AsyncThunkPendingActionCreator<ThunkArg, ThunkApiConfig = {}> = ActionCreatorWithPreparedPayload<[
|
157 | string,
|
158 | ThunkArg,
|
159 | GetPendingMeta<ThunkApiConfig>?
|
160 | ], undefined, string, never, {
|
161 | arg: ThunkArg;
|
162 | requestId: string;
|
163 | requestStatus: 'pending';
|
164 | } & GetPendingMeta<ThunkApiConfig>>;
|
165 | export declare type AsyncThunkRejectedActionCreator<ThunkArg, ThunkApiConfig = {}> = ActionCreatorWithPreparedPayload<[
|
166 | Error | null,
|
167 | string,
|
168 | ThunkArg,
|
169 | GetRejectValue<ThunkApiConfig>?,
|
170 | GetRejectedMeta<ThunkApiConfig>?
|
171 | ], GetRejectValue<ThunkApiConfig> | undefined, string, GetSerializedErrorType<ThunkApiConfig>, {
|
172 | arg: ThunkArg;
|
173 | requestId: string;
|
174 | requestStatus: 'rejected';
|
175 | aborted: boolean;
|
176 | condition: boolean;
|
177 | } & (({
|
178 | rejectedWithValue: false;
|
179 | } & {
|
180 | [K in keyof GetRejectedMeta<ThunkApiConfig>]?: undefined;
|
181 | }) | ({
|
182 | rejectedWithValue: true;
|
183 | } & GetRejectedMeta<ThunkApiConfig>))>;
|
184 | export declare type AsyncThunkFulfilledActionCreator<Returned, ThunkArg, ThunkApiConfig = {}> = ActionCreatorWithPreparedPayload<[
|
185 | Returned,
|
186 | string,
|
187 | ThunkArg,
|
188 | GetFulfilledMeta<ThunkApiConfig>?
|
189 | ], Returned, string, never, {
|
190 | arg: ThunkArg;
|
191 | requestId: string;
|
192 | requestStatus: 'fulfilled';
|
193 | } & GetFulfilledMeta<ThunkApiConfig>>;
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | export declare type AsyncThunk<Returned, ThunkArg, ThunkApiConfig extends AsyncThunkConfig> = AsyncThunkActionCreator<Returned, ThunkArg, ThunkApiConfig> & {
|
201 | pending: AsyncThunkPendingActionCreator<ThunkArg, ThunkApiConfig>;
|
202 | rejected: AsyncThunkRejectedActionCreator<ThunkArg, ThunkApiConfig>;
|
203 | fulfilled: AsyncThunkFulfilledActionCreator<Returned, ThunkArg, ThunkApiConfig>;
|
204 | typePrefix: string;
|
205 | };
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 | export declare function createAsyncThunk<Returned, ThunkArg = void>(typePrefix: string, payloadCreator: AsyncThunkPayloadCreator<Returned, ThunkArg, {}>, options?: AsyncThunkOptions<ThunkArg, {}>): AsyncThunk<Returned, ThunkArg, {}>;
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 | export declare function createAsyncThunk<Returned, ThunkArg, ThunkApiConfig extends AsyncThunkConfig>(typePrefix: string, payloadCreator: AsyncThunkPayloadCreator<Returned, ThunkArg, ThunkApiConfig>, options?: AsyncThunkOptions<ThunkArg, ThunkApiConfig>): AsyncThunk<Returned, ThunkArg, ThunkApiConfig>;
|
224 | interface UnwrappableAction {
|
225 | payload: any;
|
226 | meta?: any;
|
227 | error?: any;
|
228 | }
|
229 | declare type UnwrappedActionPayload<T extends UnwrappableAction> = Exclude<T, {
|
230 | error: any;
|
231 | }>['payload'];
|
232 |
|
233 |
|
234 |
|
235 | export declare function unwrapResult<R extends UnwrappableAction>(action: R): UnwrappedActionPayload<R>;
|
236 | declare type WithStrictNullChecks<True, False> = undefined extends boolean ? False : True;
|
237 | export {};
|