Open History to see the last commit
1---
2id: queryOptions
3title: queryOptions
4---
5β
6# Function: queryOptions()
7β
8Allows to share and re-use query options in a type-safe way.
9β
10The `queryKey` will be tagged with the type from `queryFn`.
11β
12**Example**
13β
14```ts
15const { queryKey } = queryOptions({
16 queryKey: ['key'],
17 queryFn: () => Promise.resolve(5),
18 // ^? Promise<number>
19})
20β
21const queryClient = new QueryClient()
22const data = queryClient.getQueryData(queryKey)
23// ^? number | undefined
24```
25β
26## Param
27β
28The query options to tag with the type from `queryFn`.
29β
30## Call Signature
31β
32```ts
33function queryOptions<TQueryFnData, TError, TData, TQueryKey>(
34 options,
35): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & object
36```
37β
38Allows to share and re-use query options in a type-safe way.
39β
40The `queryKey` will be tagged with the type from `queryFn`.
41β
42**Example**
43β
44```ts
45const { queryKey } = queryOptions({
46 queryKey: ['key'],
47 queryFn: () => Promise.resolve(5),
48 // ^? Promise<number>
49})
50β
51const queryClient = new QueryClient()
52const data = queryClient.getQueryData(queryKey)
53// ^? number | undefined
54```
55β
56### Type Parameters
57β
58β’ **TQueryFnData** = `unknown`
59β
60β’ **TError** = `Error`
61β
62β’ **TData** = `TQueryFnData`
63β
64β’ **TQueryKey** _extends_ readonly `unknown`[] = readonly `unknown`[]
65β
66### Parameters
67β
68#### options
69β
70[`DefinedInitialDataOptions`](../../type-aliases/definedinitialdataoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
71β
72The query options to tag with the type from `queryFn`.
73β
74### Returns
75β
76[`DefinedInitialDataOptions`](../../type-aliases/definedinitialdataoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> & `object`
77β
78The tagged query options.
79β
80The tagged query options.
81β
82### Param
83β
84The query options to tag with the type from `queryFn`.
85β
86### Defined in
87β
88[query-options.ts:78](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L78)
89β
90## Call Signature
91β
92```ts
93function queryOptions<TQueryFnData, TError, TData, TQueryKey>(
94 options,
95): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & object
96```
97β
98Allows to share and re-use query options in a type-safe way.
99β
100The `queryKey` will be tagged with the type from `queryFn`.
101β
102**Example**
103β
104```ts
105const { queryKey } = queryOptions({
106 queryKey: ['key'],
107 queryFn: () => Promise.resolve(5),
108 // ^? Promise<number>
109})
110β
111const queryClient = new QueryClient()
112const data = queryClient.getQueryData(queryKey)
113// ^? number | undefined
114```
115β
116### Type Parameters
117β
118β’ **TQueryFnData** = `unknown`
119β
120β’ **TError** = `Error`
121β
122β’ **TData** = `TQueryFnData`
123β
124β’ **TQueryKey** _extends_ readonly `unknown`[] = readonly `unknown`[]
125β
126### Parameters
127β
128#### options
129β
130[`UnusedSkipTokenOptions`](../../type-aliases/unusedskiptokenoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
131β
132The query options to tag with the type from `queryFn`.
133β
134### Returns
135β
136[`UnusedSkipTokenOptions`](../../type-aliases/unusedskiptokenoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> & `object`
137β
138The tagged query options.
139β
140The tagged query options.
141β
142### Param
143β
144The query options to tag with the type from `queryFn`.
145β
146### Defined in
147β
148[query-options.ts:111](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L111)
149β
150## Call Signature
151β
152```ts
153function queryOptions<TQueryFnData, TError, TData, TQueryKey>(
154 options,
155): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & object
156```
157β
158Allows to share and re-use query options in a type-safe way.
159β
160The `queryKey` will be tagged with the type from `queryFn`.
161β
162**Example**
163β
164```ts
165const { queryKey } = queryOptions({
166 queryKey: ['key'],
167 queryFn: () => Promise.resolve(5),
168 // ^? Promise<number>
169})
170β
171const queryClient = new QueryClient()
172const data = queryClient.getQueryData(queryKey)
173// ^? number | undefined
174```
175β
176### Type Parameters
177β
178β’ **TQueryFnData** = `unknown`
179β
180β’ **TError** = `Error`
181β
182β’ **TData** = `TQueryFnData`
183β
184β’ **TQueryKey** _extends_ readonly `unknown`[] = readonly `unknown`[]
185β
186### Parameters
187β
188#### options
189β
190[`UndefinedInitialDataOptions`](../../type-aliases/undefinedinitialdataoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
191β
192The query options to tag with the type from `queryFn`.
193β
194### Returns
195β
196[`UndefinedInitialDataOptions`](../../type-aliases/undefinedinitialdataoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> & `object`
197β
198The tagged query options.
199β
200The tagged query options.
201β
202### Param
203β
204The query options to tag with the type from `queryFn`.
205β
206### Defined in
207β
208[query-options.ts:144](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/query-options.ts#L144)