From 688bc2f7003299272c162cb2f15947cd5429aa88 Mon Sep 17 00:00:00 2001 From: jungwoo3490 Date: Sun, 15 Dec 2024 16:13:16 +0900 Subject: [PATCH] fix(react-query): fix lint ci error --- packages/openapi-react-query/src/index.ts | 83 ++++++++++++++++------- 1 file changed, 60 insertions(+), 23 deletions(-) diff --git a/packages/openapi-react-query/src/index.ts b/packages/openapi-react-query/src/index.ts index a9d2503b0..1aba524b9 100644 --- a/packages/openapi-react-query/src/index.ts +++ b/packages/openapi-react-query/src/index.ts @@ -96,8 +96,34 @@ export type UseInfiniteQueryMethod extends never - ? [InitWithUnknowns?, Omit>, "queryKey" | "queryFn">?, QueryClient?] - : [InitWithUnknowns, Omit>, "queryKey" | "queryFn">?, QueryClient?] + ? [ + InitWithUnknowns?, + Omit< + UseInfiniteQueryOptions< + Response["data"], + Response["error"], + Response["data"], + number, + QueryKey + >, + "queryKey" | "queryFn" + >?, + QueryClient?, + ] + : [ + InitWithUnknowns, + Omit< + UseInfiniteQueryOptions< + Response["data"], + Response["error"], + Response["data"], + number, + QueryKey + >, + "queryKey" | "queryFn" + >?, + QueryClient?, + ] ) => UseInfiniteQueryResult; export type UseMutationMethod>, Media extends MediaType> = < @@ -145,22 +171,30 @@ export default function createClient, - Init extends MaybeOptionalInit, - Response extends Required>, ->( - method: Method, - path: Path, - init?: InitWithUnknowns, - options?: Omit>, "queryKey" | "queryFn"> -) => ({ - queryKey: [method, path, init] as const, - queryFn, - ...options, -}); + Method extends HttpMethod, + Path extends PathsWithMethod, + Init extends MaybeOptionalInit, + Response extends Required>, + >( + method: Method, + path: Path, + init?: InitWithUnknowns, + options?: Omit< + UseInfiniteQueryOptions< + Response["data"], + Response["error"], + Response["data"], + number, + QueryKey + >, + "queryKey" | "queryFn" + >, + ) => ({ + queryKey: [method, path, init] as const, + queryFn, + ...options, + }); return { queryOptions, @@ -170,12 +204,15 @@ export default function createClient, options), queryClient), useInfiniteQuery: (method, path, ...[init, options, queryClient]) => { const baseOptions = infiniteQueryOptions(method, path, init as InitWithUnknowns, options as any); // TODO: find a way to avoid as any - return useInfiniteQuery({ - ...baseOptions, - initialPageParam: 0, - getNextPageParam: (lastPage: any, allPages: any[], lastPageParam: number, allPageParams: number[]) => - options?.getNextPageParam?.(lastPage, allPages, lastPageParam, allPageParams) ?? allPages.length, - } as any, queryClient); + return useInfiniteQuery( + { + ...baseOptions, + initialPageParam: 0, + getNextPageParam: (lastPage: any, allPages: any[], lastPageParam: number, allPageParams: number[]) => + options?.getNextPageParam?.(lastPage, allPages, lastPageParam, allPageParams) ?? allPages.length, + } as any, + queryClient, + ); }, useMutation: (method, path, options, queryClient) => useMutation(