-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix(vue-query): move queryOptions
and useQuery
function overloads
#9088
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
fix(vue-query): move queryOptions
and useQuery
function overloads
#9088
Conversation
… useQuery to come before general ones (TanStack#9069) This instructs TypeScript to pick correct function overload when initialData is defined.
bba7782
to
f48877e
Compare
View your CI Pipeline Execution ↗ for commit 835d48c.
☁️ Nx Cloud last updated this comment at |
queryOptions
and useQuery
function overloads queryOptions
and useQuery
function overloads
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9088 +/- ##
===========================================
+ Coverage 44.56% 71.10% +26.53%
===========================================
Files 203 19 -184
Lines 8101 481 -7620
Branches 1803 136 -1667
===========================================
- Hits 3610 342 -3268
+ Misses 4059 109 -3950
+ Partials 432 30 -402
🚀 New features to boost your workflow:
|
Could you check out this PR and take a look at In this PR, I tested all possible combinations of From what I can tell, the problem seems to be in |
@ss0526100 Yes, if I understand correctly the issue comes specifically from combining Because there are 2 layers of function type overloads these should be declared in correct order otherwise |
Sorry, I was mistaken. |
Fixes #9069. Unfortunately solutions from #9073 and #9077 didn't fully resolve the original issue.
I looked at what
react-query
does to ensure correct type safety for 4 different cases ofinitialData
. These are:undefined
,T
,() => T
,() => T | undefined
and how come we're seeing troubles with type inference invue-query
.So what I noticed is that react version declares overloads of
useQuery
andqueryOptions
whereinitialData
is defined before the ones whereinitialData
is undefined. But overload ordering matters. In a nutshell, more specific overload should come before a more general one. Vue was doing the opposite where definedinitialData
overloads are declared later which caused TypeScript to pick the wrong overload instead. That was causing both forbidding ofundefined
in function returns and leavingundefined
in type union fordata
.So I changed type declarations to align with
react-query
types. And it looks to be working as expected now.I also copied
initialData
type test cases fromuseQuery
intoqueryOptions
to verify that when query is usingqueryOptions
API thendata
types are still inferred correctly.