I am using joi to validate the schema of my objects. For objectid validation joi has a seperate package joi-objectid. I am using it for objectid validation. But recently when i am trying to migrate my code into typescript joi is throwing an error that objectid does not exist on joi. Since it is added at runtime we cannot get the reference. how can i override the joi types so that it supports objectid function.?
Advertisement
Answer
I had to add it to the individual files.
import Joi from "joi"; import JoiObjectId from "joi-objectid"; const myJoiObjectId = JoiObjectId(Joi); export const validateFixture = (input: object) => { const schema = { home: myJoiObjectId().required(), away: myJoiObjectId().required(), date: Joi.date(), score: Joi.object(), stadium: Joi.string().required(), played: Joi.boolean() }; return Joi.validate(input, schema); };