Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lonewarrior556 opened this issue Oct 7, 2020 · 1 comment
Open

Comments

@lonewarrior556
Copy link
Contributor

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
Copy link

i-kay commented Jan 2, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants