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
I'm writing a middleware for validating the request body, and I need to wrap the validator in a function. Here is my code:
importvine,{errors,typeVineValidator}from"@vinejs/vine";importtype{SchemaTypes,ValidationOptions}from"@vinejs/vine/types";importtype{NextFunction,Request,Response}from"express";functionrequireValidation<TextendsSchemaTypes,Uextendsundefined|Record<string,any>>(validator: VineValidator<T,U>,options?: ValidationOptions<U>){// TODO: Find a way to make `options` optionalreturnasync(req: Request,res: Response,next: NextFunction)=>{try{awaitvalidator.validate(req.body,options);next();}catch(error){if(errorinstanceoferrors.E_VALIDATION_ERROR){res.status(400).send({status: "fail",message: error.message,});}elseif(errorinstanceofError){res.status(500).send({status: "error",message: error.message,});}}};}exportdefaultrequireValidation;
I receive the following error: Argument of type '[ValidationOptions<U> | undefined]' is not assignable to parameter of type '[undefined] extends U ? [options?: ValidationOptions<U> | undefined] : [options: ValidationOptions<U>]'.ts(2345)
I don't know if this is the correct way to type this function either. I will appreciate some help!
The text was updated successfully, but these errors were encountered:
I'm writing a middleware for validating the request body, and I need to wrap the validator in a function. Here is my code:
I receive the following error:
Argument of type '[ValidationOptions<U> | undefined]' is not assignable to parameter of type '[undefined] extends U ? [options?: ValidationOptions<U> | undefined] : [options: ValidationOptions<U>]'.ts(2345)
I don't know if this is the correct way to type this function either. I will appreciate some help!
The text was updated successfully, but these errors were encountered: