Skip to content
Source
Sign inSign up
TanStack/query

fix(react-query): fix to show type error on wrong type annotation in `useQuery` #8683

Mergedskiende74(GitHub profile, opens in a new tab)merged 10 commits intomain fromrefs/pull/8683/headmerged by TkDodo View on GitHub

Showing 2 changed files with 25 additions and 4 deletions.

x
0 of 2 viewed, 2 left
16 additions and 0 deletionspackages/react-query/src/__tests__/useQuery.test-d.tsxModified
View file
@@ -277,6 +277,22 @@
​
+ // eslint-disable-next-line vitest/expect-expect
+ it('TData should depend from only arguments, not the result', () => {
+ // @ts-expect-error
+ const result: UseQueryResult<{ wow: string }> = useQuery({
+ queryKey: ['key'],
+ queryFn: () => {
+ return {
+ wow: true,
+ }
+ },
+ initialData: () => undefined as { wow: boolean } | undefined,
+ })
+​
+ void result
+ })
+​
it('data should not have undefined when initialData is provided', () => {
const { data } = useQuery({
queryKey: ['query-key'],
9 additions and 4 deletionspackages/react-query/src/useQuery.tsModified
View file
@@ -1,7 +1,12 @@
'use client'
import { QueryObserver } from '@tanstack/query-core'
import { useBaseQuery } from './useBaseQuery'