-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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(react-query
): fix useInfiniteQuery
placeholderData
types
#4402
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 task
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
@SSHari is attempting to deploy a commit to the trpc Team on Vercel. A member of the Team first needs to authorize it. |
Ensure that `useInfiniteQuery` and `useSuspenseInfiniteQuery` use explicit types rather than inferred generic types.
KATT
previously approved these changes
May 24, 2023
KATT
reviewed
May 24, 2023
packages/tests/server/regression/issue-4360-useInfiniteQuery-placeHolderData.test.tsx
Show resolved
Hide resolved
β¦laceHolderData.test.tsx
KATT
previously approved these changes
May 24, 2023
KATT
previously approved these changes
May 24, 2023
KATT
changed the title
fix(react-query): useInfiniteQuery and useSuspenseInfiniteQuery types
fix(May 24, 2023
react-query
): useInfiniteQuery and useSuspenseInfiniteQuery types
KATT
changed the title
fix(
fix(May 24, 2023
react-query
): useInfiniteQuery and useSuspenseInfiniteQuery typesreact-query
): fix useInfiniteQuery
placeholderData
types
KATT
approved these changes
May 24, 2023
mastondzn
added a commit
to mastondzn/synopsisbot
that referenced
this pull request
May 28, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@trpc/client](https://trpc.io) ([source](https://togithub.com/trpc/trpc)) | [`10.27.1` -> `10.28.0`](https://renovatebot.com/diffs/npm/@trpc%2fclient/10.27.1/10.28.0) | [![age](https://badges.renovateapi.com/packages/npm/@trpc%2fclient/10.28.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@trpc%2fclient/10.28.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@trpc%2fclient/10.28.0/compatibility-slim/10.27.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@trpc%2fclient/10.28.0/confidence-slim/10.27.1)](https://docs.renovatebot.com/merge-confidence/) | | [@trpc/react-query](https://trpc.io) ([source](https://togithub.com/trpc/trpc)) | [`10.27.1` -> `10.28.0`](https://renovatebot.com/diffs/npm/@trpc%2freact-query/10.27.1/10.28.0) | [![age](https://badges.renovateapi.com/packages/npm/@trpc%2freact-query/10.28.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@trpc%2freact-query/10.28.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@trpc%2freact-query/10.28.0/compatibility-slim/10.27.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@trpc%2freact-query/10.28.0/confidence-slim/10.27.1)](https://docs.renovatebot.com/merge-confidence/) | | [@trpc/server](https://trpc.io) ([source](https://togithub.com/trpc/trpc)) | [`10.27.1` -> `10.28.0`](https://renovatebot.com/diffs/npm/@trpc%2fserver/10.27.1/10.28.0) | [![age](https://badges.renovateapi.com/packages/npm/@trpc%2fserver/10.28.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@trpc%2fserver/10.28.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@trpc%2fserver/10.28.0/compatibility-slim/10.27.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@trpc%2fserver/10.28.0/confidence-slim/10.27.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>trpc/trpc</summary> ### [`v10.28.0`](https://togithub.com/trpc/trpc/releases/tag/v10.28.0) [Compare Source](https://togithub.com/trpc/trpc/compare/v10.27.3...v10.28.0) #### What's Changed - feat(`client`): allow closing active subscriptions by [@​Dealerpriest](https://togithub.com/Dealerpriest) in [trpc/trpc#4136 - feat(`client`): add ability to call `TRPCProxyClient`-methods with `.apply()` by [@​atoy40](https://togithub.com/atoy40) in [trpc/trpc#3973 - feat(`react-query`): allow optional cursor in `useInfiniteQuery` by [@​lithdew](https://togithub.com/lithdew) in [trpc/trpc#4374 - fix(`*`): exclude `*.test.*`-files in build outputs by [@​KATT](https://togithub.com/KATT) in [trpc/trpc#4417 #### New Contributors - [@​atoy40](https://togithub.com/atoy40) made their first contribution in [trpc/trpc#3973 - [@​miguelvelasquezdev](https://togithub.com/miguelvelasquezdev) made their first contribution in [trpc/trpc#4341 - [@​lithdew](https://togithub.com/lithdew) made their first contribution in [trpc/trpc#4374 **Full Changelog**: trpc/trpc@v10.27.3...v10.28.0 ### [`v10.27.3`](https://togithub.com/trpc/trpc/releases/tag/v10.27.3) [Compare Source](https://togithub.com/trpc/trpc/compare/v10.27.2...v10.27.3) #### What's Changed - fix(`react-query`): fix `useInfiniteQuery` `placeholderData` types by [@​SSHari](https://togithub.com/SSHari) in [trpc/trpc#4402 #### New Contributors - [@​SSHari](https://togithub.com/SSHari) made their first contribution in [trpc/trpc#4402 **Full Changelog**: trpc/trpc@v10.27.2...v10.27.3 ### [`v10.27.2`](https://togithub.com/trpc/trpc/releases/tag/v10.27.2) [Compare Source](https://togithub.com/trpc/trpc/compare/v10.27.1...v10.27.2) #### What's Changed - fix(`next)`: remove conditional hook in `withTRPC()` by [@​KATT](https://togithub.com/KATT) in [trpc/trpc#4410 **Full Changelog**: trpc/trpc@v10.27.1...v10.27.2 </details> --- ### Configuration π **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). π¦ **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. π **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/synopsisgg/bot). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMDIuNCIsInVwZGF0ZWRJblZlciI6IjM1LjEwMi40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ensure that
useInfiniteQuery
anduseSuspenseInfiniteQuery
use explicit types rather than inferred generic types.Closes #4360
Bounty: /claim #4360
π― Changes
Problem
This problem looks to be the result of our relying on a default generic parameter (e.g.):
The problem is that the way the default parameter seems to be working is that TypeScript uses the default (i.e.
string
) unless it can infer the type by some other means.In this case, we set the default value of
TData
toinferTransformedProcedureOutput<TProcedure>
, however, by returning a different type from theplaceholderData
, TypeScript tries to help us out and infer the type from what it returns. This inference supersedes the default parameter typeinferTransformedProcedureOutput<TProcedure>
.I put together a minimal example using the TS Playground to help illustrate what I mean. Essentially, TypeScript only uses the default parameter if it can't infer another type by some other means.
Solution
I'm making a bit of an assumption here which is why I'm opening this PR as a draft PR, so that a discussion can be started. Based on the idea that TRPC is intended to help create type safety by inferring types off of the router, I'm not sure there's a reason we would want to allow the types for these hooks to be overridden.
For example, I'm not sure we would expect to see the following:
Assuming that's true, then the question is why do we use generic types for the hooks. My thought is that there are two advantages:
I'm not sure how important the above two points are, but if we prefer to keep them, then an alternative solution would be to explicitly constrain the generic parameter so that invalid types can't be inferred from the
placeholderData
return:I also noticed that the
useQuery
hook also allows you to return anything from theplaceholderData
. I would think that we'd want to restrict this so you have to return the correct type for theplaceholderData
for all of the query types. That said, I held off on making more changes until we can confirm a path forward.Note: If my initial assumption is wrong and we actually do want to be able to use any type for the hook's generic parameter (i.e.
trpc.post.list.useInfiniteQuery<CustomData, CustomData>(input, opts);
), then neither of these proposed changes will work.β Checklist