-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed as not planned
Labels
Description
The following wrapper code works in 2.6.0, but fails in 2.6.1
export type AppDispatch = typeof store.dispatch;
export const dispatchAndHandleResult = async <
Returned, // The type of the return value of the thunk
ThunkArg // The type of the argument the thunk receives
>(
dispatch: AppDispatch,
action: AsyncThunk<
Returned,
ThunkArg,
{ state: RootState; dispatch: AppDispatch; rejectValue: string }
>,
args: ThunkArg,
onSuccess?: (result: Returned) => void,
onFailure?: (error?: string) => void
) => {
const actionResult = await dispatch(action(args));
if (isFulfilled(actionResult)) {
if (onSuccess) onSuccess(actionResult.payload);
} else if (isRejected(actionResult)) {
if (onFailure) onFailure(actionResult.payload);
}
};The reported problem from args in await dispatch(action(args));
TS2345: Argument of type 'ThunkArg' is not assignable to parameter of type 'ThunkArg & undefined'.
Type 'ThunkArg' is not assignable to type 'undefined'.