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
docs: fix header and body generic types #2103
Conversation
The generic short-hand types follow order `<Query = DefaultQuery, Params = DefaultParams, Headers = DefaultHeaders, Body = DefaultBody>` but the docs has them listed as `<Query, Params, Body, Headers>`. This caused one of the examples to be incorrect when it assigned `unknown` to the `Headers` type but explained that it was `unknown` on the `Body` type. The body was undefined which mean it would default to `DefaultBody` which is `any`
console.log(request.body) // this is of type unknown! | ||
console.log(request.headers) // this is of type fastify.DefaultHeader because typescript will use the default type value! | ||
console.log(request.headers) // this is of type unknown! | ||
console.log(request.body) // this is of type fastify.DefaultBody because typescript will use the default type value! |
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 was the easiest correction to make to be valid, however I think it does take the value of example down a bit.
I thought the example was trying to make the case for Body
being unknown
and because no value was given for headers it defaults to DefaultHeaders
; however, when the type ordering is corrected if we keep the example there is not a way to specify unknown
for body without defining type for headers which means the example is no longer applicable. This is why I only switched the order.
console.log(request.headers) // this is of type Headers! | ||
console.log(request.body) // this is of type Body! |
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.
These re-orders aren't required, but I think it's more clear to follow the order of types. Body being last one.
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.
LGTM. Great work on this
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. |
The generic short-hand types follow order
<Query = DefaultQuery, Params = DefaultParams, Headers = DefaultHeaders, Body = DefaultBody>
but the docs has them listed as
<Query, Params, Body, Headers>
. This caused one of the examples to be incorrect when it assignedunknown
to theHeaders
type but explained that it wasunknown
on theBody
type. The body was undefined which mean it would default toDefaultBody
which isany
Checklist
npm run test
andnpm run benchmark