Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

infinite-query-options.ts

125 lines2.8 KB

1import type {
2 DataTag,
3 DefaultError,
4 InfiniteData,
5 QueryKey,
6} from '@tanstack/query-core'
7import type { CreateInfiniteQueryOptions, NonUndefinedGuard } from './types'
8​
9/**
10 * @public
11 */
12export type UndefinedInitialDataInfiniteOptions<
13 TQueryFnData,
14 TError = DefaultError,
15 TData = InfiniteData<TQueryFnData>,
16 TQueryKey extends QueryKey = QueryKey,
17 TPageParam = unknown,
18> = CreateInfiniteQueryOptions<
19 TQueryFnData,
20 TError,
21 TData,
22 TQueryFnData,
23 TQueryKey,
24 TPageParam
25> & {
26 initialData?: undefined
28​
29/**
30 * @public
31 */
32export type DefinedInitialDataInfiniteOptions<
33 TQueryFnData,
34 TError = DefaultError,
35 TData = InfiniteData<TQueryFnData>,
36 TQueryKey extends QueryKey = QueryKey,
37 TPageParam = unknown,
38> = CreateInfiniteQueryOptions<
39 TQueryFnData,
40 TError,
41 TData,
42 TQueryFnData,
43 TQueryKey,
44 TPageParam
45> & {
46 initialData:
47 | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
48 | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
50​
51/**
52 * Allows to share and re-use infinite query options in a type-safe way.
53 *
54 * The `queryKey` will be tagged with the type from `queryFn`.
55 * @param options - The infinite query options to tag with the type from `queryFn`.
56 * @returns The tagged infinite query options.
57 * @public
58 */
59export function infiniteQueryOptions<
60 TQueryFnData,
61 TError = DefaultError,
62 TData = InfiniteData<TQueryFnData>,
63 TQueryKey extends QueryKey = QueryKey,
64 TPageParam = unknown,
65>(
66 options: DefinedInitialDataInfiniteOptions<
67 TQueryFnData,
68 TError,
69 TData,
70 TQueryKey,
71 TPageParam
72 >,
73): DefinedInitialDataInfiniteOptions<
74 TQueryFnData,
75 TError,
76 TData,
77 TQueryKey,
78 TPageParam
79> & {
80 queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
82​
83/**
84 * Allows to share and re-use infinite query options in a type-safe way.
85 *
86 * The `queryKey` will be tagged with the type from `queryFn`.
87 * @param options - The infinite query options to tag with the type from `queryFn`.
88 * @returns The tagged infinite query options.
89 * @public
90 */
91export function infiniteQueryOptions<
92 TQueryFnData,
93 TError = DefaultError,
94 TData = InfiniteData<TQueryFnData>,
95 TQueryKey extends QueryKey = QueryKey,
96 TPageParam = unknown,
97>(
98 options: UndefinedInitialDataInfiniteOptions<
99 TQueryFnData,
100 TError,
101 TData,
102 TQueryKey,
103 TPageParam
104 >,
105): UndefinedInitialDataInfiniteOptions<
106 TQueryFnData,
107 TError,
108 TData,
109 TQueryKey,
110 TPageParam
111> & {
112 queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
114​
115/**
116 * Allows to share and re-use infinite query options in a type-safe way.
117 *
118 * The `queryKey` will be tagged with the type from `queryFn`.
119 * @param options - The infinite query options to tag with the type from `queryFn`.
120 * @returns The tagged infinite query options.
121 * @public
122 */
123export function infiniteQueryOptions(options: unknown) {
124 return options