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

fix(server): inference fix for inputs with middleware #5017

Merged
merged 8 commits into from
Nov 10, 2023
Merged

Conversation

KATT
Copy link
Member

@KATT KATT commented Nov 9, 2023

Closes #

🎯 Changes

What changes are made in this PR? Is it a feature or a bug fix?

βœ… 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.

Copy link

vercel bot commented Nov 9, 2023

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
next-prisma-starter βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 9, 2023 10:19pm
og-image βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 9, 2023 10:19pm
trpc-next-app-dir βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 9, 2023 10:19pm
www βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 9, 2023 10:19pm

@KATT KATT added the πŸ› bug Something isn't working label Nov 9, 2023
Comment on lines 36 to 40
type Input = AppRouterInputs['strWithMiddleware'];
// ^?
type Output = AppRouterOutputs['strWithMiddleware'];
expectTypeOf<Input>().toBeString();
expectTypeOf<Output>().toBeString();
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the one that's failing

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this happens because of Overwrite<string, string> which results in the garbled nonsense you're seeing in the inferred type.

This part is obviously the culprit -- it needs some handling to only overwrite in cases that make sense. I might not have time to work on this right now or in the coming days but I'll try something tonight if I can

  _input_in: UnsetMarker extends TNext['_input_in']
    ? TPrev['_input_in']
    : Overwrite<TPrev['_input_in'], TNext['_input_in']>;
  _input_out: UnsetMarker extends TNext['_input_out']
    ? TPrev['_input_out']
    : Overwrite<TPrev['_input_out'], TNext['_input_out']>

Copy link
Contributor

@jussisaurio jussisaurio Nov 9, 2023

Choose a reason for hiding this comment

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

I think the proper solution would be a sane implementation of Overwrite that only does things you'd expect. Example pseudo:

Given A and B,

- If they are both objects, overwrite A's keys with B's keys
- If only A is object, return A
- If only B is object, return B
- If A extends any, return A
- If B extends any, return B
- Otherwise return never

But are there any other practical usecases for Overwrite?

EDIT: alternative pseudo:

- If they are both objects, overwrite A's keys with B
- If both extend any, return B
- Otherwise return the one that extends any, or if neither: never

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes more sense for an intuitive meaning of "Overwrite" so that key-wise overwrite happens when both are objects, and otherwise TWith just replaces TType entirely.

KATT and others added 8 commits November 10, 2023 00:07
Overwrite<string,string> resulted in a mangled object type
because the existing implementation iterated over the string
type's keys (e.g. 'charCodeAt')

This commit changes the implementation so that keys are only
iterated and overwritten in the case of objects. Otherwise,
a non-never TWith type will entirely replace TType, e.g.
Overwrite<string, number> results in 'number'.
@KATT KATT merged commit f27d50c into main Nov 10, 2023
37 checks passed
@KATT KATT deleted the inference-fix branch November 10, 2023 10:08
renovate bot added a commit to ettorepuccetti/terrarossa that referenced this pull request Nov 10, 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.43.2` ->
`10.43.3`](https://renovatebot.com/diffs/npm/@trpc%2fclient/10.43.2/10.43.3)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@trpc%2fclient/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@trpc%2fclient/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@trpc%2fclient/10.43.2/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@trpc%2fclient/10.43.2/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [@trpc/next](https://trpc.io)
([source](https://togithub.com/trpc/trpc)) | [`10.43.2` ->
`10.43.3`](https://renovatebot.com/diffs/npm/@trpc%2fnext/10.43.2/10.43.3)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@trpc%2fnext/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@trpc%2fnext/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@trpc%2fnext/10.43.2/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@trpc%2fnext/10.43.2/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [@trpc/react-query](https://trpc.io)
([source](https://togithub.com/trpc/trpc)) | [`10.43.2` ->
`10.43.3`](https://renovatebot.com/diffs/npm/@trpc%2freact-query/10.43.2/10.43.3)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@trpc%2freact-query/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@trpc%2freact-query/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@trpc%2freact-query/10.43.2/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@trpc%2freact-query/10.43.2/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [@trpc/server](https://trpc.io)
([source](https://togithub.com/trpc/trpc)) | [`10.43.2` ->
`10.43.3`](https://renovatebot.com/diffs/npm/@trpc%2fserver/10.43.2/10.43.3)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@trpc%2fserver/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@trpc%2fserver/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@trpc%2fserver/10.43.2/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@trpc%2fserver/10.43.2/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>trpc/trpc (@&#8203;trpc/client)</summary>

### [`v10.43.3`](https://togithub.com/trpc/trpc/releases/tag/v10.43.3)

[Compare
Source](https://togithub.com/trpc/trpc/compare/v10.43.2...v10.43.3)

#### What's Changed

- fix(server): inference fix for inputs using primitives with middleware
by [@&#8203;jussisaurio](https://togithub.com/jussisaurio) &
[@&#8203;KATT](https://togithub.com/KATT) in
[trpc/trpc#5017

#### New Contributors

- [@&#8203;junya-ishibuchi](https://togithub.com/junya-ishibuchi) made
their first contribution in
[trpc/trpc#5023

**Full Changelog**:
trpc/trpc@v10.43.2...v10.43.3

</details>

---

### Configuration

πŸ“… **Schedule**: Branch creation - "after 3am,before 9am" (UTC),
Automerge - "after 3am,before 9am" (UTC).

🚦 **Automerge**: Enabled.

β™» **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://developer.mend.io/github/ettorepuccetti/terrarossa).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot added a commit to dotkom/monoweb that referenced this pull request Nov 13, 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.43.0` ->
`^10.43.3`](https://renovatebot.com/diffs/npm/@trpc%2fclient/10.43.0/10.43.3)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@trpc%2fclient/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@trpc%2fclient/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@trpc%2fclient/10.43.0/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@trpc%2fclient/10.43.0/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [@trpc/next](https://trpc.io)
([source](https://togithub.com/trpc/trpc)) | [`^10.43.0` ->
`^10.43.3`](https://renovatebot.com/diffs/npm/@trpc%2fnext/10.43.0/10.43.3)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@trpc%2fnext/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@trpc%2fnext/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@trpc%2fnext/10.43.0/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@trpc%2fnext/10.43.0/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [@trpc/react-query](https://trpc.io)
([source](https://togithub.com/trpc/trpc)) | [`^10.43.0` ->
`^10.43.3`](https://renovatebot.com/diffs/npm/@trpc%2freact-query/10.43.0/10.43.3)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@trpc%2freact-query/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@trpc%2freact-query/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@trpc%2freact-query/10.43.0/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@trpc%2freact-query/10.43.0/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [@trpc/server](https://trpc.io)
([source](https://togithub.com/trpc/trpc)) | [`^10.43.0` ->
`^10.43.3`](https://renovatebot.com/diffs/npm/@trpc%2fserver/10.43.0/10.43.3)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@trpc%2fserver/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@trpc%2fserver/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@trpc%2fserver/10.43.0/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@trpc%2fserver/10.43.0/10.43.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>trpc/trpc (@&#8203;trpc/client)</summary>

### [`v10.43.3`](https://togithub.com/trpc/trpc/releases/tag/v10.43.3)

[Compare
Source](https://togithub.com/trpc/trpc/compare/v10.43.2...v10.43.3)

##### What's Changed

- fix(server): inference fix for inputs using primitives with middleware
by [@&#8203;jussisaurio](https://togithub.com/jussisaurio) &
[@&#8203;KATT](https://togithub.com/KATT) in
[trpc/trpc#5017

##### New Contributors

- [@&#8203;junya-ishibuchi](https://togithub.com/junya-ishibuchi) made
their first contribution in
[trpc/trpc#5023

**Full Changelog**:
trpc/trpc@v10.43.2...v10.43.3

### [`v10.43.2`](https://togithub.com/trpc/trpc/releases/tag/v10.43.2)

[Compare
Source](https://togithub.com/trpc/trpc/compare/v10.43.1...v10.43.2)

##### What's Changed

- fix(next): omit "fetch" from options by
[@&#8203;withyellow](https://togithub.com/withyellow) in
[trpc/trpc#5003

##### New Contributors

- [@&#8203;spirobel](https://togithub.com/spirobel) made their first
contribution in
[trpc/trpc#5007
- [@&#8203;AvaYnE2](https://togithub.com/AvaYnE2) made their first
contribution in
[trpc/trpc#4835
- [@&#8203;withyellow](https://togithub.com/withyellow) made their first
contribution in
[trpc/trpc#5003

**Full Changelog**:
trpc/trpc@v10.43.1...v10.43.2

### [`v10.43.1`](https://togithub.com/trpc/trpc/releases/tag/v10.43.1)

[Compare
Source](https://togithub.com/trpc/trpc/compare/v10.43.0...v10.43.1)

##### What's Changed

- fix(server + client): incorrect inferred input type when using
standalone middleware by
[@&#8203;jussisaurio](https://togithub.com/jussisaurio) in
[trpc/trpc#4973
- fix(server + client): fix some issues with inferring Record types as
procedure outputs by
[@&#8203;jussisaurio](https://togithub.com/jussisaurio) in
[trpc/trpc#4986

##### New Contributors

- [@&#8203;MadaShindeInai](https://togithub.com/MadaShindeInai) made
their first contribution in
[trpc/trpc#4979

**Full Changelog**:
trpc/trpc@v10.43.0...v10.43.1

</details>

---

### Configuration

πŸ“… **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

β™» **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://developer.mend.io/github/dotkom/monoweb).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
KATT added a commit that referenced this pull request Nov 17, 2023
---------

Co-authored-by: KATT <alexander@n1s.se>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
πŸ› bug Something isn't working @trpc/server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants