Type 'string' is not assignable to type '"string" | "number" | "boolean" | "undefined" | "object" | "function"'
isaachinman opened this issue · 2 comments
Hi there - very interesting idea here! Unfortunately I'm unable to get your project to compile after installing types-joi
and copy/pasting the example from your test suite:
const schema = joi
.object({
test: joi
.string()
.required()
.default('baz')
.valid('baz' as const, 'bar' as const),
val: joi.number().optional(),
inner: joi
.object({
a: joi.string(),
b: joi.number(),
})
.required(),
values: joi
.array()
.required()
.items(joi.string().required()),
buf: joi.binary().required(),
})
.required();
type SchemaInterface = InterfaceFrom<typeof schema>;
I get the following error:
Type 'ObjectSchema' does not satisfy the constraint 'BaseSchema<any>'.
Types of property 'schemaType' are incompatible.
Type 'string' is not assignable to type '"string" | "number" | "boolean" | "undefined" | "object" | "function"'.
I'm curious if you're using this package in any active projects? Is this an error on my part?
@isaachinman yes, it's being used by multiple projects.
Please, make sure you are using at least TypeScript 3.4
Yes, we're up to date on our TS dep. After taking a closer look at the docs, I realised you expect users to import joi
from this package. I had completely missed that on the first pass over - I imagine many other people will miss this too if it's not explicitly stated:
import * as joi from "types-joi";
Although I haven't had a chance to retry my use case with this new knowledge, I will close this issue for now and come back later if anything arises.
Thanks, and best of luck!