Skip to content

Commit 8c7c0e5

Browse files
phryneasLenz Weber
authored and
Lenz Weber
committed
createAsyncThunk: add rejectWithValue function
1 parent a6e5e5f commit 8c7c0e5

File tree

5 files changed

+199
-58
lines changed

5 files changed

+199
-58
lines changed

etc/redux-toolkit.api.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,21 @@ export function createAction<P = void, T extends string = string>(type: T): Payl
103103
export function createAction<PA extends PrepareAction<any>, T extends string = string>(type: T, prepareAction: PA): PayloadActionCreator<ReturnType<PA>['payload'], T, PA>;
104104

105105
// @alpha (undocumented)
106-
export function createAsyncThunk<Returned, ThunkArg = void, ThunkApiConfig extends AsyncThunkConfig = {}>(type: string, payloadCreator: (arg: ThunkArg, thunkAPI: GetThunkAPI<ThunkApiConfig>) => Promise<Returned> | Returned): ((arg: ThunkArg) => (dispatch: GetDispatch<ThunkApiConfig>, getState: () => GetState<ThunkApiConfig>, extra: GetExtra<ThunkApiConfig>) => Promise<PayloadAction<Returned, string, {
106+
export function createAsyncThunk<Returned, ThunkArg = void, ThunkApiConfig extends AsyncThunkConfig = {}>(type: string, payloadCreator: (arg: ThunkArg, thunkAPI: GetThunkAPI<ThunkApiConfig>) => Promise<Returned | RejectWithValue<GetRejectValue<ThunkApiConfig>>> | Returned | RejectWithValue<GetRejectValue<ThunkApiConfig>>): ((arg: ThunkArg) => (dispatch: GetDispatch<ThunkApiConfig>, getState: () => GetState<ThunkApiConfig>, extra: GetExtra<ThunkApiConfig>) => Promise<PayloadAction<Returned, string, {
107107
arg: ThunkArg;
108108
requestId: string;
109-
}, never> | PayloadAction<undefined, string, {
109+
}, never> | PayloadAction<GetRejectValue<ThunkApiConfig> | undefined, string, {
110110
arg: ThunkArg;
111111
requestId: string;
112112
aborted: boolean;
113-
}, any>> & {
113+
}, SerializedError>> & {
114114
abort: (reason?: string | undefined) => void;
115115
}) & {
116116
pending: ActionCreatorWithPreparedPayload<[string, ThunkArg], undefined, string, never, {
117117
arg: ThunkArg;
118118
requestId: string;
119119
}>;
120-
rejected: ActionCreatorWithPreparedPayload<[Error, string, ThunkArg], undefined, string, any, {
120+
rejected: ActionCreatorWithPreparedPayload<[Error | null, string, ThunkArg, (GetRejectValue<ThunkApiConfig> | undefined)?], GetRejectValue<ThunkApiConfig> | undefined, string, SerializedError, {
121121
arg: ThunkArg;
122122
requestId: string;
123123
aborted: boolean;
@@ -284,11 +284,7 @@ export type SliceCaseReducers<State> = {
284284
export { ThunkAction }
285285

286286
// @alpha (undocumented)
287-
export function unwrapResult<T>(returned: {
288-
error: any;
289-
} | {
290-
payload: NonNullable<T>;
291-
}): NonNullable<T>;
287+
export function unwrapResult<R extends ActionTypesWithOptionalErrorAction>(returned: R): PayloadForActionTypesExcludingErrorActions<R>;
292288

293289
// @alpha (undocumented)
294290
export type Update<T> = {

package-lock.json

Lines changed: 46 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@types/json-stringify-safe": "^5.0.0",
2929
"@types/nanoid": "^2.1.0",
3030
"@types/node": "^10.14.4",
31+
"axios": "^0.19.2",
3132
"console-testing-library": "^0.3.1",
3233
"eslint-config-react-app": "^5.0.1",
3334
"invariant": "^2.2.4",

0 commit comments

Comments
 (0)