-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix(react-query): fix to show type error on wrong type annotation in useQuery
#8683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
useQuery
packages/react-query/src/useQuery.ts
Outdated
|
||
export function useQuery(options: UseQueryOptions, queryClient?: QueryClient) { | ||
return useBaseQuery(options, QueryObserver, queryClient) | ||
} | ||
|
||
type NoInfer<T> = [T][T extends any ? 0 : never] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have a NoInfer
util, you should be able to import it from the query-core
package
Thanks for your review, @TkDodo! import { NoInfer } from 'query-core/util'; Could you please take another look? |
View your CI Pipeline Execution ↗ for commit 568788e.
☁️ Nx Cloud last updated this comment at |
![]() @skiende74 Resolve eslint error in /packages/react-query/src/tests/useQuery.test-d.tsx please |
@manudeli |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8683 +/- ##
===========================================
+ Coverage 44.53% 84.22% +39.68%
===========================================
Files 204 26 -178
Lines 8150 374 -7776
Branches 1820 111 -1709
===========================================
- Hits 3630 315 -3315
+ Misses 4077 50 -4027
+ Partials 443 9 -434
🚀 New features to boost your workflow:
|
closes #7530
This should produce a type error because the correct type for queryResult should be
UseQueryResult<string>
.Previously, due to reverse type inference from the return type context, no error was detected when using the wrong type annotation.
This PR prevents reverse type inference from the result type annotation, ensuring that incorrect type annotations are caught as type errors.