-
-
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(server): inference fix for inputs with middleware #5017
Conversation
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
type Input = AppRouterInputs['strWithMiddleware']; | ||
// ^? | ||
type Output = AppRouterOutputs['strWithMiddleware']; | ||
expectTypeOf<Input>().toBeString(); | ||
expectTypeOf<Output>().toBeString(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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']>
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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'.
c9a489b
to
7dc04a7
Compare
[![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 (@​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 [@​jussisaurio](https://togithub.com/jussisaurio) & [@​KATT](https://togithub.com/KATT) in [trpc/trpc#5017 #### New Contributors - [@​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>
[![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 (@​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 [@​jussisaurio](https://togithub.com/jussisaurio) & [@​KATT](https://togithub.com/KATT) in [trpc/trpc#5017 ##### New Contributors - [@​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 [@​withyellow](https://togithub.com/withyellow) in [trpc/trpc#5003 ##### New Contributors - [@​spirobel](https://togithub.com/spirobel) made their first contribution in [trpc/trpc#5007 - [@​AvaYnE2](https://togithub.com/AvaYnE2) made their first contribution in [trpc/trpc#4835 - [@​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 [@​jussisaurio](https://togithub.com/jussisaurio) in [trpc/trpc#4973 - fix(server + client): fix some issues with inferring Record types as procedure outputs by [@​jussisaurio](https://togithub.com/jussisaurio) in [trpc/trpc#4986 ##### New Contributors - [@​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>
Closes #
π― Changes
What changes are made in this PR? Is it a feature or a bug fix?
β Checklist