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
As of v17.5.0, the above code does not compile. The compiler reports the following:
demo.ts:18:5 - error TS2322: Type 'ObjectSchema<Name>' is not assignable to type'ObjectSchema<StrictSchemaMap<Name>>'.
Types of property 'concat' are incompatible.
Type '(schema: ObjectSchema<Name>) => ObjectSchema<Name>' is not assignable to type'(schema: ObjectSchema<StrictSchemaMap<Name>>) => ObjectSchema<StrictSchemaMap<Name>>'.
Types of parameters 'schema' and 'schema' are incompatible.
Type 'ObjectSchema<StrictSchemaMap<Name>>' is not assignable to type'ObjectSchema<Name>'.
The types returned by 'validate(...)' are incompatible between these types.
Type 'ValidationResult<StrictSchemaMap<Name>>' is not assignable to type'ValidationResult<Name>'.
Type '{ error: undefined; warning?: ValidationError | undefined; value: StrictSchemaMap<Name>; }' is not assignable to type'ValidationResult<Name>'.
Type '{ error: undefined; warning?: ValidationError | undefined; value: StrictSchemaMap<Name>; }' is not assignable to type'{ error: undefined; warning?: ValidationError | undefined; value: Name; }'.
Types of property 'value' are incompatible.
Type 'StrictSchemaMap<Name>' is not assignable to type'Name'.
18 name: nameSchema
What result did you expect?
I would expect the code to compile without issues.
If I change this line:
constcustomerSchema=Joi.object<Customer,true>({
...to this:
constcustomerSchema=Joi.object<Customer>({
...then the code compiles, but I lose the safety of strict object schemas.
The text was updated successfully, but these errors were encountered:
I am experiencing the same problem. It seems the return type of joi.object<Type, true>() returns an ObjectSchema without the strict typing applied on its generic type.
That PR added isStrict to Joi.object, but then requires that any schema nested inside a strict schema must have the type ObjectSchema<StrictSchemaMap<T>>, which isn't possible because Joi.object returns ObjectSchema<T> whether it is strict or not. Even the example given in the PR doesn't work anymore with those changes.
I think I'll open a new PR to fix the issue.
LeoAso
added a commit
to LeoAso/joi
that referenced
this issue
May 21, 2022
Context
What are you trying to achieve or the steps to reproduce?
When I nest an object schema inside of another, strict object schema, I expect no type issues. For example, the following code compiles in v17.4.3:
What was the result you got?
As of v17.5.0, the above code does not compile. The compiler reports the following:
What result did you expect?
I would expect the code to compile without issues.
If I change this line:
...to this:
...then the code compiles, but I lose the safety of strict object schemas.
The text was updated successfully, but these errors were encountered: