From 6fb352b0f17e4deb16e6ad0107ae8adf6c0caa57 Mon Sep 17 00:00:00 2001 From: Cam Jackson <1930451+camjackson@users.noreply.github.com> Date: Wed, 24 Sep 2025 21:59:11 +1000 Subject: [PATCH] docs(react-query): add caveat for typing getQueriesData --- docs/framework/react/typescript.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/framework/react/typescript.md b/docs/framework/react/typescript.md index d9fe0319ed..59f56d3268 100644 --- a/docs/framework/react/typescript.md +++ b/docs/framework/react/typescript.md @@ -237,6 +237,13 @@ Without `queryOptions`, the type of `data` would be `unknown`, unless we'd pass const data = queryClient.getQueryData(['groups']) ``` +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: + +```ts +const entries = queryClient.getQueriesData(groupOptions().queryKey) +// ^? const entries: Array<[QueryKey, Group[] | undefined]> +``` + ## Typing Mutation Options Similarly to `queryOptions`, you can use `mutationOptions` to extract mutation options into a separate function: