Type ... is not assignable to type 'never'.ts(2322)
Closed this issue ยท 2 comments
guyellis commented
I'm getting the error described in the comments at the bottom of the example below which is also available in a repo here.
Am I just approaching this incorrectly or is this something that can be fixed in this repo?
import joi from '@hapi/joi';
import 'joi-extract-type';
const testSchema = joi
.object({
tractor: joi
.array()
.has(
joi.object({
myId: joi
.string()
.optional(),
})
)
.required()
.min(1),
})
.required();
type TestType = joi.extractType<typeof testSchema>;
const tf = (): TestType => {
return {
tractor: [{ myId: '1' }]
};
// On myId above I'm getting this TypeScript error:
// (property) myId: string
// Type 'string' is not assignable to type 'never'.ts(2322)
}
TCMiranda commented
Hey @guyellis I think .has
is not implemented.
Any reason to use .has
instead of .items
?
Actually I haven't used .has
myself, and I am not sure how it would map to a type since the implementation says that it is valid if at least one of array items match the schema.
guyellis commented
@TCMiranda - no reason not to use items - that works - thanks!