fix: ReplyTypeConstrainer array type inference#4885
Conversation
Make sure the reply type is a valid object with only http codes as keys
|
Hey @mcollina could you take a look again? Found an issue with the previous type definition: The type has an invalid status code, and |
|
I have to be honest: I personally dont know, if this PR means regressions in other cases. |
|
@climba03003 @fox1t wdyt? |
types/reply.d.ts
Outdated
|
|
||
| type ReplyTypeConstrainer<RouteGenericReply, Code extends ReplyKeysToCodes<keyof RouteGenericReply>> = | ||
| RouteGenericReply extends HttpCodesReplyType & Record<Exclude<keyof RouteGenericReply, keyof HttpCodesReplyType>, never> ? | ||
| Code extends keyof RouteGenericReply ? Required<RouteGenericReply[Code]> : |
There was a problem hiding this comment.
I am not sure if Required is needed.
It is actually changing the original generic to all property must exist, doesn't it?
There was a problem hiding this comment.
There was a problem hiding this comment.
True, it's not needed at all. Just removed it.
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [fastify](https://www.fastify.io/) ([source](https://togithub.com/fastify/fastify)) | [`4.20.0` -> `4.21.0`](https://renovatebot.com/diffs/npm/fastify/4.20.0/4.21.0) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>fastify/fastify (fastify)</summary> ### [`v4.21.0`](https://togithub.com/fastify/fastify/releases/tag/v4.21.0) [Compare Source](https://togithub.com/fastify/fastify/compare/v4.20.0...v4.21.0) #### What's Changed - chore: remove license-checker package by [@​Uzlopak](https://togithub.com/Uzlopak) in [https://github.com/fastify/fastify/pull/4914](https://togithub.com/fastify/fastify/pull/4914) - chore: remove pump devDependency by [@​Uzlopak](https://togithub.com/Uzlopak) in [https://github.com/fastify/fastify/pull/4913](https://togithub.com/fastify/fastify/pull/4913) - ci: create artifacts in coverage workflows by [@​Uzlopak](https://togithub.com/Uzlopak) in [https://github.com/fastify/fastify/pull/4909](https://togithub.com/fastify/fastify/pull/4909) - docs(server): grammar and structure fixes by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify/pull/4904](https://togithub.com/fastify/fastify/pull/4904) - docs: Fix typo in TypeScript docs ("[@​types/node](https://togithub.com/types/node)", not "[@​node/types](https://togithub.com/node/types)") by [@​jasongwartz](https://togithub.com/jasongwartz) in [https://github.com/fastify/fastify/pull/4922](https://togithub.com/fastify/fastify/pull/4922) - \[readme] add CII Best Practices Badge by [@​ljharb](https://togithub.com/ljharb) in [https://github.com/fastify/fastify/pull/4926](https://togithub.com/fastify/fastify/pull/4926) - fix: lowercase type-providers headers types by [@​toomuchdesign](https://togithub.com/toomuchdesign) in [https://github.com/fastify/fastify/pull/4928](https://togithub.com/fastify/fastify/pull/4928) - ERR_REP_ALREADY_SENT hint that a route may be missing "return reply" by [@​mcollina](https://togithub.com/mcollina) in [https://github.com/fastify/fastify/pull/4921](https://togithub.com/fastify/fastify/pull/4921) - fix: ReplyTypeConstrainer array type inference by [@​pedroescumalha](https://togithub.com/pedroescumalha) in [https://github.com/fastify/fastify/pull/4885](https://togithub.com/fastify/fastify/pull/4885) #### New Contributors - [@​jasongwartz](https://togithub.com/jasongwartz) made their first contribution in [https://github.com/fastify/fastify/pull/4922](https://togithub.com/fastify/fastify/pull/4922) - [@​ljharb](https://togithub.com/ljharb) made their first contribution in [https://github.com/fastify/fastify/pull/4926](https://togithub.com/fastify/fastify/pull/4926) - [@​toomuchdesign](https://togithub.com/toomuchdesign) made their first contribution in [https://github.com/fastify/fastify/pull/4928](https://togithub.com/fastify/fastify/pull/4928) - [@​pedroescumalha](https://togithub.com/pedroescumalha) made their first contribution in [https://github.com/fastify/fastify/pull/4885](https://togithub.com/fastify/fastify/pull/4885) **Full Changelog**: fastify/fastify@v4.20.0...v4.21.0 </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 this update 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/tomacheese/telcheck). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yNC4yIiwidXBkYXRlZEluVmVyIjoiMzYuMjQuMiIsInRhcmdldEJyYW5jaCI6Im1hc3RlciJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [fastify](https://www.fastify.io/) ([source](https://togithub.com/fastify/fastify)) | [`4.20.0` -> `4.21.0`](https://renovatebot.com/diffs/npm/fastify/4.20.0/4.21.0) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>fastify/fastify (fastify)</summary> ### [`v4.21.0`](https://togithub.com/fastify/fastify/releases/tag/v4.21.0) [Compare Source](https://togithub.com/fastify/fastify/compare/v4.20.0...v4.21.0) #### What's Changed - chore: remove license-checker package by [@​Uzlopak](https://togithub.com/Uzlopak) in [https://github.com/fastify/fastify/pull/4914](https://togithub.com/fastify/fastify/pull/4914) - chore: remove pump devDependency by [@​Uzlopak](https://togithub.com/Uzlopak) in [https://github.com/fastify/fastify/pull/4913](https://togithub.com/fastify/fastify/pull/4913) - ci: create artifacts in coverage workflows by [@​Uzlopak](https://togithub.com/Uzlopak) in [https://github.com/fastify/fastify/pull/4909](https://togithub.com/fastify/fastify/pull/4909) - docs(server): grammar and structure fixes by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify/pull/4904](https://togithub.com/fastify/fastify/pull/4904) - docs: Fix typo in TypeScript docs ("[@​types/node](https://togithub.com/types/node)", not "[@​node/types](https://togithub.com/node/types)") by [@​jasongwartz](https://togithub.com/jasongwartz) in [https://github.com/fastify/fastify/pull/4922](https://togithub.com/fastify/fastify/pull/4922) - \[readme] add CII Best Practices Badge by [@​ljharb](https://togithub.com/ljharb) in [https://github.com/fastify/fastify/pull/4926](https://togithub.com/fastify/fastify/pull/4926) - fix: lowercase type-providers headers types by [@​toomuchdesign](https://togithub.com/toomuchdesign) in [https://github.com/fastify/fastify/pull/4928](https://togithub.com/fastify/fastify/pull/4928) - ERR_REP_ALREADY_SENT hint that a route may be missing "return reply" by [@​mcollina](https://togithub.com/mcollina) in [https://github.com/fastify/fastify/pull/4921](https://togithub.com/fastify/fastify/pull/4921) - fix: ReplyTypeConstrainer array type inference by [@​pedroescumalha](https://togithub.com/pedroescumalha) in [https://github.com/fastify/fastify/pull/4885](https://togithub.com/fastify/fastify/pull/4885) #### New Contributors - [@​jasongwartz](https://togithub.com/jasongwartz) made their first contribution in [https://github.com/fastify/fastify/pull/4922](https://togithub.com/fastify/fastify/pull/4922) - [@​ljharb](https://togithub.com/ljharb) made their first contribution in [https://github.com/fastify/fastify/pull/4926](https://togithub.com/fastify/fastify/pull/4926) - [@​toomuchdesign](https://togithub.com/toomuchdesign) made their first contribution in [https://github.com/fastify/fastify/pull/4928](https://togithub.com/fastify/fastify/pull/4928) - [@​pedroescumalha](https://togithub.com/pedroescumalha) made their first contribution in [https://github.com/fastify/fastify/pull/4885](https://togithub.com/fastify/fastify/pull/4885) **Full Changelog**: fastify/fastify@v4.20.0...v4.21.0 </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 this update 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/redwoodjs/redwood). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yNy4xIiwidXBkYXRlZEluVmVyIjoiMzYuMjcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Closes #4883
As @aadito123 mentioned on the issue, there's a pitfall here: if someone wants the Reply type to be an object with keys as http codes like
{ 401: string, 409: string }, the inference of the return type will bestring. A possible workaround for this case would be{ '4xx': { 401: string, 409: string } }.Checklist
npm run testandnpm run benchmarkand the Code of conduct