setQueryData doesn't give typehints #8490
Replies: 2 comments
|
This can only work if you |
|
The reason The most ergonomic fix is to define the query with import { queryOptions } from '@tanstack/react-query'
const postOptions = (id: number) => queryOptions({
queryKey: ['posts', id] as const,
queryFn: () => fetchPost(id),
})Then: const { data } = useQuery(postOptions(id))
queryClient.setQueryData(postOptions(id).queryKey, (old) => {
if (!old) return old
return { ...old, title: 'Updated' }
})Now If you don't want to refactor yet, the short-term fix is just: queryClient.setQueryData<Post>(['posts', id], updater)But |
Uh oh!
There was an error while loading. Please reload this page.
Hi I'd like some help please. My useQuery is typed but my setQueryData typing doesn't work.
So this is my useQuery.


Elsewhere in the application, I setQueryData and it gives type unknown.

If it helps, my

queryKeyslooks likeI was under the impression that you got type hints if the queryKey was a const.
Any help would be awesome.
Thanks.
All reactions