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

docs: fix header and body generic types #2103

Merged
merged 1 commit into from Feb 18, 2020
Merged

Conversation

mattmazzola
Copy link
Contributor

@mattmazzola mattmazzola commented Feb 17, 2020

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

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

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!
Copy link
Contributor Author

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!
Copy link
Contributor Author

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.

Copy link
Member

@Ethan-Arrowood Ethan-Arrowood left a 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

@Eomm Eomm added documentation Improvements or additions to documentation typescript TypeScript related labels Feb 18, 2020
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation typescript TypeScript related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants