我在打字稿项目中使用react-query,并且在尝试将 useMutation() 挂钩与 graphql 查询一起使用时遇到难以解释的类型错误。
示例代码:
useMutation(
async (
parameter1: string,
parameter2: string
) => {
const response = await sdk.myMutation({
parameter1: parameter1,
parameter2: parameter2,
});
return response;
},
{
onSettled: () => queryClient.invalidateQueries([CACHE_KEY]),
}
);
Run Code Online (Sandbox Code Playgroud)
类型错误:
No overload matches this call.
Overload 1 of 4, '(mutationFn: MutationFunction<{ __typename: "IdResponse"; id: string; }, string>, options?: Omit<UseMutationOptions<{ __typename: "IdResponse"; id: string; }, unknown, string, unknown>, "mutationFn"> | undefined): UseMutationResult<...>', gave the following error.
Argument of type '(parameter1: string, parameter2: string) => …Run Code Online (Sandbox Code Playgroud)