added generic Query, Params, Headers, and Body types#1160
Merged
mcollina merged 4 commits intofastify:masterfrom Sep 17, 2018
jineshshah36:master
Merged
added generic Query, Params, Headers, and Body types#1160mcollina merged 4 commits intofastify:masterfrom jineshshah36:master
mcollina merged 4 commits intofastify:masterfrom
jineshshah36:master
Conversation
Contributor
Author
|
As an example how I can use this in a real-world example: However, they are all optional, so I could also do the following: And finally, as it's non-breaking, this also works and automatically infers defaults: |
Member
|
Good work! Can you add that example to our tests as well? |
Contributor
Author
|
I added tests and a section in the typescript docs explaining how to use it. |
21 tasks
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
npm run testandnpm run benchmarkFirst off, this is a completely non-breaking change for typescript users. The main change here is that I converted the query, params, headers, and body types into generics that default to the existing type definitions. Since we can set the schema validators, I think it makes sense to also allow us to exactly type the pieces that can be validated since we will know exactly what their types should be. However, this should not be required which is why I defaulted these new generic types to their existing values, making this feature completely opt-in for typescript users.
Right now, overriding one of the generic types will be slightly verbose since typescript cannot infer generic parameters when one is overridden out of order, but generic parameter type inference is already on their roadmap for 3.2 (microsoft/TypeScript#26349). My opinion is that this should be merged now since it isn't breaking, and once 3.2 comes out, it will only be easier.