Skip to content

Support intersections #2495

Open
Open
@sguillia

Description

@sguillia

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:

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    typesTypeScript type definitions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions