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