Skip to content

Commit cd29063

Browse files
authored
docs(react-query): add caveat for typing getQueriesData (#9684)
1 parent 4d8da1e commit cd29063

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

docs/framework/react/typescript.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ Without `queryOptions`, the type of `data` would be `unknown`, unless we'd pass
237237
const data = queryClient.getQueryData<Group[]>(['groups'])
238238
```
239239

240+
Note that type inference via `queryOptions` does _not_ work for `queryClient.getQueriesData`, because it returns an array of tuples with heterogeneous, `unknown` data. If you are sure of the type of data that your query will return, specify it explicitly:
241+
242+
```ts
243+
const entries = queryClient.getQueriesData<Group[]>(groupOptions().queryKey)
244+
// ^? const entries: Array<[QueryKey, Group[] | undefined]>
245+
```
246+
240247
## Typing Mutation Options
241248

242249
Similarly to `queryOptions`, you can use `mutationOptions` to extract mutation options into a separate function:

0 commit comments

Comments
 (0)