hapijs / hapijs/joi

Support intersections

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

Description

#### Support plan

* *is this issue currently blocking your project?* yes
* *is this issue affecting a production system?* no

#### Context

* *node version*: v12.4.0
* *module version*: joi 17.2.1
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*: n/a

#### How can we help?

Hi!

I can't find any way to write the schema for the following Typescript types. This is what I've tried:

```js
import Joi from "@hapi/joi"

type Bar1 = {}
type Bar2 = {}
type Bar = Bar1 | Bar2
type Contents = {}
type Foo = Bar & Contents

const Bar1 = Joi.object()
const Bar2 = Joi.object()
const Bar = Joi.alternatives().try(Bar1, Bar2)
const Contents = Joi.object()
const Foo = Bar.concat(Contents) // compile error
```

It says

> Argument of type 'ObjectSchema' is not assignable to parameter of type 'AlternativesSchema'.

Note I need to have 5 separate schemas, I cannot write one big schema mixing up all 5 types

Do you have any advice on how to approach the problem?

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.