-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Describe the bug
It looks like that there are breaking changes in 2.8.0 for TypeScript users in useMutation:
In 2.7.1, use Mutation was typed as:
export function useMutation<TResult, TVariables = undefined, TError = Error, TSnapshot = unknown>(
mutationFn: MutationFunction<TResult, TVariables, TError, TSnapshot>,
mutationOptions?: MutationOptions<TResult, TVariables, TError, TSnapshot>
): MutationResultPair<TResult, TVariables, TError>https://unpkg.com/browse/react-query@2.7.1/types/index.d.ts
Now in 2.8.0, TVariables and TError have swapped their places:
export declare function useMutation<TResult, TError = unknown, TVariables = undefined, TSnapshot = unknown(
mutationFn: MutationFunction<TResult, TVariables>,
config?: MutationConfig<TResult, TError, TVariables, TSnapshot>
): MutationResultPair<TResult, TError, TVariables, TSnapshot>;https://unpkg.com/browse/react-query@2.8.0/types/react/useMutation.d.ts
This results in TS Errors for the code which was working in 2.7.1:
return useMutation<void, { items: string[]; otherItems: string[] }>(async ({ items, otherItems }) => {
...
});Error: TS2339: Property 'items' does not exist on type 'undefined'.
By adding e.g. any as second generic to the useMutation function everything is working as expected again.
Expected behavior
I would have expected that the signature of the method didn't change in a minor release. Anyhow, I think this is not a really big issue which would require a rollback of that change, but it should be mentioned in the release for example so that TypeScript users know how to deal with this issue.