AlternativeSchema interpreted as 'never'
Closed this issue ยท 4 comments
omairvaiyani commented
const schema = Joi.object({
type: Joi.string().required(),
foo: Joi.alternatives().when('type', {
is: 'something',
then: Joi.array()
.items(Joi.string())
.required(),
otherwise: Joi.forbidden()
})
});
type Thing = Joi.extractType<typeof schema>;
const thing: Thing = {
type: 'something',
foo: [] // error, foo: never cannot be assigned to any[]
}
This is a really kick-ass library, I've become very reliant on it since we don't have to duplicate our types + schemas with it! Thank you!
TCMiranda commented
Hey @omairvaiyani nice to hear that!
So, I didn't work on alternatives().when
. At first It would be easy to go with #2 extracting the type as A | B
.
Ill try to work on it soon to implement a basic support.
omairvaiyani commented
That's great, good luck. I'd love to submit a PR, but my internal typescript knowledge is primitive unfortunately.
TCMiranda commented
Actually, I've improved a lot since I started this project ๐
The basic support is published @0.1.5
omairvaiyani commented
That was quick, thank you!