用打字稿反应查询

react query with typescript

我正在尝试使用 React 查询从这个函数中获取一些数据。

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, {

      });

打字稿给我这个错误:

Argument of type '(id: string, bankAccountInformation: IBankAccountInformation, quotaLegal?: string | undefined) => Promise' is not assignable to parameter of type 'QueryFunction<string, QueryKey>'.ts(2345)

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

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