用打字稿反应查询

时间:2021-05-22 20:10:10

标签: typescript react-query

我正在尝试使用 react guery 从这个函数中获取一些 sata。

export const quotaReservationRefundServiceBankAccount = (
  id: string,
  bankAccountInformation: IBankAccountInformation,
  quotaLegal?: string,
): Promise<Response> => {
  const url = `${appSettings.bffUrl}/api/pregnancies/quotareservations/${id}/bankaccount/refund`;
  const body: IRefundQuotaReservationRequest = {
    language: appSettings.language,
    bankAccountInformation,
    legalDepartmentShortCode: quotaLegal || "",
  };
  return post(url, body);
};

我得到了这个票价:

  const { data: testData, isLoading, error } = useQuery<string, IBankAccountInformation, string | undefined>(["bankRefundResponse",  quota?.reservation || "Quota.reservation missing", bankAccountInfo, quota.legal], quotaReservationRefundServiceBankAccount, {

      });

打字稿给了我这个错误:

<块引用>

'(id: string, bankAccountInformation: IBankAccountInformation, quotaLegal?: string |未定义) => Promise' 不可分配给类型的参数 'QueryFunction'.ts(2345)

1 个答案:

答案 0 :(得分:0)

参数通过 queryKey 传递给 queryFn,因此您可以破坏 queryKey(queryFn 的第一个参数)或仅使用内联函数:

useQuery(["key", id, bankAccountInformation, quota], () => quotaReservationRefundServiceBankAccount(id, bankAccountInformation, quota))