Skip to content

Types of alternative are wrong always resolves to any #2980

@felixmosh

Description

@felixmosh

Support plan

  • is this issue currently blocking your project? (yes):
  • is this issue affecting a production system? (no):

Context

  • node version: 18
  • module version with issue: 17.9.2
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information:

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

const hostSchema = Joi.alternatives([Joi.string().ip(), Joi.string().domain().allow('localhost')]).required();

What was the result you got?

hostSchema gets a type of Joi.AlternativesSchema<any> instead of specific union of types,
image

What result did you expect?

It should contain reflect the union type of the alternatives...

Maybe we can use the types from https://github.com/maghis/types-joi/blob/master/index.d.ts which do work

The problem is that SchemaLike is not related to the TSchema, In addition, Typescript doesn't supports rest params of different types, therefore, we probably need to do what is done here

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportQuestions, discussions, and general support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions