Skip to content

Improperly typed mutation hook onError & onSettled #2518

@sacha-c

Description

@sacha-c

openapi-react-query version

0.5.1

Description

The useMutation hook appears to have incorrectly typed options, which prevent the result of the onMutate callback to be used as parameters to the onError and onSettled callbacks.

I believe the cause to be the type definitions here: https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-react-query/src/index.ts#L159, where UseMutationOptions is set without generic parameter for TOnMutateResult which then gets set to unknown instead of the proper type.

I am not well-versed enough in types to fully understand the underlying issue so the problem could be elsewhere, or it may be an issue of the version of react-query which I have (@tanstack/react-query@5.90.6), but I think this projects supports this version so I believe this to be more of a bug.

I also noticed this issue #2485, which potentially could provide a workaround for this issue (if it properly types those mutation options there), however it should still be possible to use mutation options the way I am trying to do so here.

Reproduction

A minimal reproduction can be found here: sacha-c@cff269d

which simply adds the following, in which we can see that the mutation options are unknown instead of the result of the onMutate callback. I would expect the type to be { someArray: Array<number>, someString: string }

Image

Expected result

I expect the types of the onSettled & onError functions of the useMutation hook to be typed with the result from the onMutate function.

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-react-queryRelevant to openapi-react-query

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions