-
-
Notifications
You must be signed in to change notification settings - Fork 623
TS generics support for checkSchema function #829
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
base: master
Are you sure you want to change the base?
Conversation
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.
We can't default to any when no type is specified because ValidationChain would not override it.
// this is the result we get
(req: any, res: any, next: any): voidThe only solution is the one suggested, but I'm not 100% satisfied with that.
/cc @gustavohenke
| import { ContextBuilder } from '../context-builder'; | ||
|
|
||
| export function check( | ||
| export function check<Req = any, Res = any, NextFn = any>( |
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.
| export function check<Req = any, Res = any, NextFn = any>( | |
| export function check<Req = Request, Res = any, NextFn = (error?: any => void)>( |
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.
I would even go one step further and make it Req extends Request instead
| const protectedNames = ['errorMessage', 'in']; | ||
|
|
||
| export function checkSchema(schema: Schema, defaultLocations: Location[] = validLocations) { | ||
| export function checkSchema<Req = any, Res = any, NextFn = any>( |
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.
| export function checkSchema<Req = any, Res = any, NextFn = any>( | |
| export function checkSchema<Req = Request, Res = any, NextFn = (error?: any => void)>( |
3177f64 to
6e160b1
Compare
No description provided.