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
Infer the type of the req object from the schema definition #1207
Comments
Hey! Yeah this is something I've been thinking of adding to express-validator. It's a pretty hard problem to solve via schemas or not:
With the above said, I'm definitely open to seeing a PR that implements this feature on top of #1000 (I've been actively working on it). I like how you approached wildcards, the use of template literals is very smart! 😄 |
Problem
Ideally when writing a schema we'd have the req type as an output. A great example of it is can be found in the zod documentation:
Having that feature will be a game changer and allow more users to stay with and adopt express-validator all while enjoying first class end to end type safety.
Solution
I've made a poc in a stackblitz that allows just this for number, strings and arrays. You can see it on the link below:
https://stackblitz.com/edit/node-q8k43c?file=tests%2Findex.ts
I'd like to hear from the owners if you like that approach so I'll know if I should be working on it as a part of express-validator or as an external library.
@gustavohenke @ctavan @liqiang372 @fedeci
The text was updated successfully, but these errors were encountered: