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-querydoes to ensure correct type safety for 4 different cases ofinitialData. These are:undefined,T,() => T,() => T | undefinedand how come we're seeing troubles with type inference invue-query.So what I noticed is that react version declares overloads of
useQueryandqueryOptionswhereinitialDatais defined before the ones whereinitialDatais undefined. But overload ordering matters. In a nutshell, more specific overload should come before a more general one. Vue was doing the opposite where definedinitialDataoverloads are declared later which caused TypeScript to pick the wrong overload instead. That was causing both forbidding ofundefinedin function returns and leavingundefinedin type union fordata.So I changed type declarations to align with
react-querytypes. And it looks to be working as expected now.I also copied
initialDatatype test cases fromuseQueryintoqueryOptionsto verify that when query is usingqueryOptionsAPI thendatatypes are still inferred correctly.