Skip to content
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

feat(react-query): allow optional cursor in useInfiniteQuery #4374

Merged
merged 6 commits into from
May 25, 2023

Conversation

lithdew
Copy link
Contributor

@lithdew lithdew commented May 17, 2023

🎯 Changes

Suppose we define a router procedure's input with Zod as z.object({ cursor: z.string().optional() }).default({}). The inferred input type, which may be checked using inferRouterInputs<Router>["procedure"], erroneously is the type union void | {cursor?: string} | undefined.

The error is caused by inferProcedureInput union-ing the input type with void should the input potentially be undefined.

useInfiniteQuery at the moment is only exposed for procedures whose inputs solely extend {cursor?: any}. Procedures whose inputs are potentially undefined, that guarantee** after parsing to set defaults to the cursor field however should also expose useInfiniteQuery.

This PR relaxes the input types of useInfiniteQuery to allow inputs that are potentially undefined by exposing useInfiniteQuery for procedures whose inputs extends the type {cursor?: any} | void.

✅ Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

@lithdew lithdew requested a review from a team as a code owner May 17, 2023 09:01
@vercel
Copy link

vercel bot commented May 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 25, 2023 1:37pm

@vercel
Copy link

vercel bot commented May 17, 2023

@lithdew is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@KATT KATT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want some tests on this - you can see #4378 for reference.

Since it's only typescript-stuff, you can wrap it in ignoreErrors(() => and add some tests type tests.

@KATT KATT changed the title fix(react-query): relax input type conditions for exposing useInfiniteQuery feat(react-query): relax input type conditions for exposing useInfiniteQuery May 18, 2023
@lithdew lithdew force-pushed the main branch 2 times, most recently from f973b05 to 81ed5ae Compare May 18, 2023 16:15
@lithdew
Copy link
Contributor Author

lithdew commented May 18, 2023

I want some tests on this - you can see #4378 for reference.

Since it's only typescript-stuff, you can wrap it in ignoreErrors(() => and add some tests type tests.

Wrote some type-checking tests to ensure that useInfiniteQuery is exposed on procedures whose inputs are optional.

…teQuery

Suppose we define a router procedure's input with Zod as `z.object({
cursor: z.string().optional() }).default({})`. The inferred input type,
which may be checked using `inferRouterInputs<Router>["procedure"]`,
erroneously is the type union `void | {cursor?: string} | undefined`.

The error is caused by `inferProcedureInput` union-ing the input
type with void should the input potentially be undefined.

useInfiniteQuery at the moment is only exposed for procedures whose
inputs solely extend `{cursor?: any}`. Procedures whose inputs are
potentially undefined, that guarantee** after parsing to set defaults to
the `cursor` field however should also expose useInfiniteQuery.

This PR relaxes the input types of useInfiniteQuery to allow inputs that
are potentially undefined by exposing useInfiniteQuery for procedures
whose inputs extends the type `{cursor?: any} | void`.
@KATT KATT changed the title feat(react-query): relax input type conditions for exposing useInfiniteQuery feat(react-query): allow optional cursor in useInfiniteQuery May 25, 2023
KATT
KATT previously approved these changes May 25, 2023
@KATT KATT merged commit 3918faf into trpc:main May 25, 2023
mastondzn referenced this pull request in mastondzn/synopsisbot 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
[@&#8203;Dealerpriest](https://togithub.com/Dealerpriest) in
[https://github.com/trpc/trpc/pull/4136](https://togithub.com/trpc/trpc/pull/4136)
- feat(`client`): add ability to call `TRPCProxyClient`-methods with
`.apply()` by [@&#8203;atoy40](https://togithub.com/atoy40) in
[https://github.com/trpc/trpc/pull/3973](https://togithub.com/trpc/trpc/pull/3973)
- feat(`react-query`): allow optional cursor in `useInfiniteQuery` by
[@&#8203;lithdew](https://togithub.com/lithdew) in
[https://github.com/trpc/trpc/pull/4374](https://togithub.com/trpc/trpc/pull/4374)
- fix(`*`): exclude `*.test.*`-files in build outputs by
[@&#8203;KATT](https://togithub.com/KATT) in
[https://github.com/trpc/trpc/pull/4417](https://togithub.com/trpc/trpc/pull/4417)

#### New Contributors

- [@&#8203;atoy40](https://togithub.com/atoy40) made their first
contribution in
[https://github.com/trpc/trpc/pull/3973](https://togithub.com/trpc/trpc/pull/3973)
- [@&#8203;miguelvelasquezdev](https://togithub.com/miguelvelasquezdev)
made their first contribution in
[https://github.com/trpc/trpc/pull/4341](https://togithub.com/trpc/trpc/pull/4341)
- [@&#8203;lithdew](https://togithub.com/lithdew) made their first
contribution in
[https://github.com/trpc/trpc/pull/4374](https://togithub.com/trpc/trpc/pull/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
[@&#8203;SSHari](https://togithub.com/SSHari) in
[https://github.com/trpc/trpc/pull/4402](https://togithub.com/trpc/trpc/pull/4402)

#### New Contributors

- [@&#8203;SSHari](https://togithub.com/SSHari) made their first
contribution in
[https://github.com/trpc/trpc/pull/4402](https://togithub.com/trpc/trpc/pull/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
[@&#8203;KATT](https://togithub.com/KATT) in
[https://github.com/trpc/trpc/pull/4410](https://togithub.com/trpc/trpc/pull/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-->
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants