Skip to content

overly restrictive return typing for onSuccess handler #2166

@quantizor

Description

@quantizor

Describe the bug

At present, onSuccess() may return a promise that the library will await to finish processing a query/mutation result. However, that typing is restricted to a promise that explicitly returns void, rather than any which would be more appropriate.

To Reproduce

Fire an async mutation and in the onSuccess, return another async mutation that is meant to happen using the data from the first. TS issues a compiler error because mutateAsync does not resolve to Promise<void>.

Expected behavior
The accepted return type for onSuccess should be Promise<any> so you can do whatever you want to in the onSuccess handler.

Current mitigation
This can currently be worked around by recasting the onSuccess return:

mutateAsync1(payload, {
  onSuccess(data) {
    return (mutateAsync2(data.token) as unknown) as Promise<void>
  }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions