You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the Request and Response types are defined without any easy way to override them.
I would like to be able to either supply generic response types or extended request types for a given route which allows me to have clearly defined types for the input/output of that route.
E.g if I have a route that should return a given shape of JSON, currently the .json method on response expects any, however if I could define the route with a Response type of a given shape, typescript would fail to compile if I had implemented the transformation in my route wrong.
And for request extension, one use case is you have middleware that does your validation, so by the time you get to your route, you know the shape of your request. E.g which path params are present, or query string params are required and so on. It would be nice to be able to define a request extension for that route to avoid unnecessary checks or casting or non null assertions.
I'm happy to work on this and submit a couple of PRs, but would be keen to get some feedback first of all on how we'd want this to work / any considerations that need to be taken into account before hand.
@naorpeled I would definitely love to see the support for generics. Have you had a chance to think about this?
Hey, yes 🙏
What @jrbarnard suggested sounds great.
I'm planning on working on it, if anyone else wants to let me know 🙏
Sorry it's taking a long time
Currently the
Request
andResponse
types are defined without any easy way to override them.I would like to be able to either supply generic response types or extended request types for a given route which allows me to have clearly defined types for the input/output of that route.
E.g if I have a route that should return a given shape of JSON, currently the
.json
method on response expectsany
, however if I could define the route with a Response type of a given shape, typescript would fail to compile if I had implemented the transformation in my route wrong.And for request extension, one use case is you have middleware that does your validation, so by the time you get to your route, you know the shape of your request. E.g which path params are present, or query string params are required and so on. It would be nice to be able to define a request extension for that route to avoid unnecessary checks or casting or non null assertions.
I'm happy to work on this and submit a couple of PRs, but would be keen to get some feedback first of all on how we'd want this to work / any considerations that need to be taken into account before hand.
A rough code example:
The text was updated successfully, but these errors were encountered: