小编Jam*_*ill的帖子

React Query useMutation - “没有重载与此调用匹配”

我在打字稿项目中使用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)

typescript graphql react-query

5
推荐指数
1
解决办法
7221
查看次数

标签 统计

graphql ×1

react-query ×1

typescript ×1