-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
refactor(*): improved type inference for useQueries with skipToken #7484
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit f3ebf03. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f3ebf03:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7484 +/- ##
===========================================
+ Coverage 43.79% 78.15% +34.35%
===========================================
Files 183 90 -93
Lines 7021 1474 -5547
Branches 1535 319 -1216
===========================================
- Hits 3075 1152 -1923
+ Misses 3580 267 -3313
+ Partials 366 55 -311 |
thanks. does this fix this issue, too? if so, can you please add another type test for it? |
…Token
…kipToken
Yes, I’ve confirmed that it also resolves issue #7496. • This improvement has been applied to other adapters (Angular, Solid, Svelte, Vue) as well. |
some of the useQueries tests in vue are failing now:
|
All done! Please check for conflicts. @TkDodo |
there are conflicts now ... |
on your PR, please address the conflicts yourself. Thanks. |
The conflicts were caused by file name changes in that PR, and now everything is perfect! @TkDodo |
Summary
This PR includes three type inference improvements.
1️⃣ Accurate Type Inference When SkipToken is Present
This issue was previously fixed (#7150), but it has reoccurred due to various modifications. Upon investigation, it appears that the root cause of the issue is the unique symbol of the
skipToken
. A unique symbol represents a single specific symbol value, and TypeScript checks this very strictly. When aqueryFn
that includes a skipToken is provided in a readonly or const state (immutable literal value), type inference works correctly. However, in general, when declared with askipToken
, type inference does not work.The current solution involves type widening for the symbol, which resolves the issue. With this approach, there is no longer a need for ReadonlyArray (as const). However, this might not work correctly in a JavaScript environment. Through type widening, a symbol other than SkipToken’s symbol might behave similarly. (In a TypeScript environment, this would be detected as a type error early on.) What do you think about this approach? I would like to hear your opinions.
2️⃣ The type inference process for GetUseQueryOptionsForUseQueries has been simplified, yet it performs more accurate type inference.
3️⃣ The type inference process for GetUseQueryResult has been simplified.