Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript fail with ThunkArg #4885

Open
MrMamen opened this issue Mar 10, 2025 · 1 comment
Open

Typescript fail with ThunkArg #4885

MrMamen opened this issue Mar 10, 2025 · 1 comment

Comments

@MrMamen
Copy link

MrMamen commented Mar 10, 2025

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'.

@MrMamen MrMamen changed the title Typescript fail wiht ThunkArk Typescript fail with ThunkArg Mar 10, 2025
@EskiMojo14
Copy link
Collaborator

will be caused by #4860

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants