hapijs / hapijs/joi

Typings for `concat` broken in v17.5.0

Open
#2,717 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

#### Context

* *node version*: 14
* *module version with issue*: 17.5.0
* *last module version without issue*: 17.4.2
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): hapi
* *any other relevant information*:

#### What are you trying to achieve or the steps to reproduce?

Given the following related schemas:

```ts
interface IInterfaceA {
baz: string;
}

interface IInterfaceB extends IInterfaceA {
foo: string;
bar: string;
}

export const dataSchemaA = Joi.object({
baz: Joi.string(),
});

export const dataSchemaB = Joi.object({
foo: Joi.string(),
bar: Joi.string(),
})
.concat(dataSchemaA) // <= typescript error here
.required();
```

#### What was the result you got?

```
Argument of type 'ObjectSchema' is not assignable to parameter of type 'ObjectSchema'.
The types returned by 'validate(...)' are incompatible between these types.
Type 'ValidationResult' is not assignable to type 'ValidationResult'.
Type '{ error: undefined; warning?: ValidationError | undefined; value: IInterfaceA; }' is not assignable to type 'ValidationResult'.
Type '{ error: undefined; warning?: ValidationError | undefined; value: IInterfaceA; }' is not assignable to type '{ error: undefined; warning?: ValidationError | undefined; value: IInterfaceB; }'.
Types of property 'value' are incompatible.
Type 'IInterfaceA' is not assignable to type 'IInterfaceB'.ts(2345)
```

#### What result did you expect?

No error. It appears that `concat` is trying to check if `InterfaceA` applies to `InterfaceB`, when it should be checking that `InterfaceA` is a subset of `InterfaceB` instead.

I think this may be related to the following recent change: https://github.com/sideway/joi/pull/2703

If this is not in fact a bug and my implementation is incorrect, any help would be greatly appreciated :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.