用打字稿反应查询

Com*_*ool 4 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);
};
Run Code Online (Sandbox Code Playgroud)

我得到的是这个票价:

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

      });
Run Code Online (Sandbox Code Playgroud)

打字稿给了我这个错误:

类型为“(id: string,bankAccountInformation: IBankAccountInformation,quotaLegal?: string | undefined) => Promise”的参数不可分配给类型为“QueryFunction<string, QueryKey>”的参数。ts(2345)

TkD*_*odo 8

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

useQuery(["key", id, bankAccountInformation, quota], () => quotaReservationRefundServiceBankAccount(id, bankAccountInformation, quota))
Run Code Online (Sandbox Code Playgroud)