Open History to see the last commit
1import type {
2 DataTag,
3 DefaultError,
4 InfiniteData,
5 InfiniteQueryObserverOptions,
6 QueryKey,
7} from '@tanstack/query-core'
8β
9/**
10 * Brands infinite query options so the `queryKey` carries the infinite query
11 * data and error types across TanStack Query APIs.
12 * @param options - Infinite query options to preserve and brand.
13 * @returns The same options object with a typed `queryKey`.
14 * @example
15 * ```ts
16 * import { infiniteQueryOptions } from '@tanstack/lit-query'
17 *
18 * const projectsOptions = infiniteQueryOptions({
19 * queryKey: ['projects'],
20 * queryFn: ({ pageParam }) => fetchProjects(pageParam),
21 * initialPageParam: 0,
22 * getNextPageParam: (lastPage) => lastPage.nextCursor,
23 * })
24 * ```
25 */
26export function infiniteQueryOptions<
27 TQueryFnData = unknown,
28 TError = DefaultError,
29 TData = InfiniteData<TQueryFnData>,
30 TQueryKey extends QueryKey = QueryKey,
31 TPageParam = unknown,
32>(
33 options: InfiniteQueryObserverOptions<
34 TQueryFnData,
35 TError,
36 TData,
37 TQueryKey,
38 TPageParam
39 >,
40): InfiniteQueryObserverOptions<
41 TQueryFnData,
42 TError,
43 TData,
44 TQueryKey,
45 TPageParam
46> & {
47 queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
48}
49β
50export function infiniteQueryOptions(options: unknown) {
51 return options
52}