Skip to content

Commit 084dcb7

Browse files
committed
docs(react-query): add caveat for typing getQueriesData
1 parent 4d8da1e commit 084dcb7

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

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`, as this function can return data of varying types and is therefore `unknown`. If you are sure of the types that your query will return, you can specify it explicitly:
241+
242+
```ts
243+
const data = queryClient.getQueriesData<Group>(groupOptions().queryKey)
244+
// ^? const data: 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)