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
used with (e.g. hapi application, another framework, standalone, ...): feathersjs
How can we help?
I'm trying to write multiple custom extensions for Joi using Typescript. The problem is, Joi.extend() seems to be returning "any" type which totally breaks autocomplete. I tried arranging my extension in the following way:
`import mongoose from 'mongoose'
import Joi from '@hapi/joi';
export function ExtendJoiWithObjectId(root: T) {
interface ExtendedStringSchema {
objectId(): ExtendedStringSchema;
}
interface ObjectIdJoi {
string(): ExtendedStringSchema;
}
return root.extend((joi) => {
return {
type: 'objectId',
base: joi.string(),
messages: {
'objectId.valid': '"{{#label}}" must be a valid mongo id'
},
coerce(value, helpers) {
return { value };
},
validate(value, helpers) {
if (!mongoose.isValidObjectId(value)) {
return helpers.error('objectId.valid');
}
}
};
}) as ObjectIdJoi;
}`
but it makes extensions impossible to combine with each other. Is there any good pattern that would allow me to extend Joi and combine all extensions in a single type definition?
The text was updated successfully, but these errors were encountered:
Support plan
Context
How can we help?
I'm trying to write multiple custom extensions for Joi using Typescript. The problem is,
Joi.extend()
seems to be returning "any" type which totally breaks autocomplete. I tried arranging my extension in the following way:`import mongoose from 'mongoose'
import Joi from '@hapi/joi';
export function ExtendJoiWithObjectId(root: T) {
}`
but it makes extensions impossible to combine with each other. Is there any good pattern that would allow me to extend Joi and combine all extensions in a single type definition?
The text was updated successfully, but these errors were encountered: