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## queryOptions(options)
31β
32```ts
33function queryOptions<TQueryFnData, TError, TData, TQueryKey>(
34 options,
35): UndefinedInitialDataOptions<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_ `QueryKey` = `QueryKey`
65β
66### Parameters
67β
68β’ **options**: [`UndefinedInitialDataOptions`](../type-aliases/undefinedinitialdataoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
69β
70The query options to tag with the type from `queryFn`.
71β
72### Returns
73β
74[`UndefinedInitialDataOptions`](../type-aliases/undefinedinitialdataoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> & `object`
75β
76The tagged query options.
77β
78The tagged query options.
79β
80### Param
81β
82The query options to tag with the type from `queryFn`.
83β
84### Defined in
85β
86[query-options.ts:52](https://github.com/TanStack/query/blob/dac5da5416b82b0be38a8fb34dde1fc6670f0a59/packages/angular-query-experimental/src/query-options.ts#L52)
87β
88## queryOptions(options)
89β
90```ts
91function queryOptions<TQueryFnData, TError, TData, TQueryKey>(
92 options,
93): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & object
94```
95β
96Allows to share and re-use query options in a type-safe way.
97β
98The `queryKey` will be tagged with the type from `queryFn`.
99β
100**Example**
101β
102```ts
103const { queryKey } = queryOptions({
104 queryKey: ['key'],
105 queryFn: () => Promise.resolve(5),
106 // ^? Promise<number>
107})
108β
109const queryClient = new QueryClient()
110const data = queryClient.getQueryData(queryKey)
111// ^? number | undefined
112```
113β
114### Type Parameters
115β
116β’ **TQueryFnData** = `unknown`
117β
118β’ **TError** = `Error`
119β
120β’ **TData** = `TQueryFnData`
121β
122β’ **TQueryKey** _extends_ `QueryKey` = `QueryKey`
123β
124### Parameters
125β
126β’ **options**: [`DefinedInitialDataOptions`](../type-aliases/definedinitialdataoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
127β
128The query options to tag with the type from `queryFn`.
129β
130### Returns
131β
132[`DefinedInitialDataOptions`](../type-aliases/definedinitialdataoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> & `object`
133β
134The tagged query options.
135β
136The tagged query options.
137β
138### Param
139β
140The query options to tag with the type from `queryFn`.
141β
142### Defined in
143β
144[query-options.ts:85](https://github.com/TanStack/query/blob/dac5da5416b82b0be38a8fb34dde1fc6670f0a59/packages/angular-query-experimental/src/query-options.ts#L85)