TCMiranda/joi-extract-type

Arrays lose all type information if they are allowed to be null

Opened this issue · 1 comments

simple example

import Joi from '@hapi/joi';
import 'joi-extract-type';

var schema = Joi.object({
  one: Joi.array().items({ a: Joi.string().required() }),
  two: Joi.array().items({ a: Joi.string().required() }).allow(null),
});

type Extracted = Joi.extractType<typeof schema>;

image

packages

    "@hapi/joi": "15.1.1",
    "joi-extract-type": "15.0.8",
    "@types/hapi__joi": "15.0.4",
i-kay commented

Also, when writing Joi code like this Joi.array().items(Joi.string()).required().allow(null), it infers (string | null)[] but I think it would be string[] | null.

image