question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional array / tuple elements

See original GitHub issue

I have defined a tuple type with an optional element like this:

type tuple23 = [ number, string, string | undefined ];

The translation I get is:

{
    "$schema": "http://json-schema.org/draft-06/schema#",
    "additionalItems": {
        "anyOf": [
            {
                "type": "number"
            },
            {
                "type": "string"
            },
            {
                "type": "string"
            }
        ]
    },
    "items": [
        {
            "type": "number"
        },
        {
            "type": "string"
        },
        {
            "type": "string"
        }
    ],
    "minItems": 3,
    "type": "array"
}

The problem is that the undefined has been lost: minItems should be 2. What I expect is:

{
    "$schema": "http://json-schema.org/draft-06/schema#",
    "items": [
        {
            "type": "number"
        },
        {
            "type": "string"
        },
        {
            "type": "string"
        }
    ],
    "minItems": 2,
    "maxItems": 3,
    "type": "array"
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
auroranilcommented, Jul 17, 2018

Same thing happens for me: When using type Array<SomeInterface | null>, typescript-json-schema ignores the null type in the “items” property.

0reactions
ali-habibzadehcommented, Jan 15, 2021

Same issue here. Undefined is missing. something?: number | undefined; in an array becomes

{"type":"object","properties":{"something":{"type":"number"}

and undefined just goes puff!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional tuple elements - Learn React with TypeScript 3 [Book]
The final tuple enhancement in TypeScript 3 is the ability to have optional elements. Optional elements are specified using a ? at the...
Read more >
How to Make Elements of a TypeScript Tuple Optional?
Starting with TypeScript v3, You can make the elements of a tuple optional by marking them with ? , for example, like so:...
Read more >
JSON Schema array tuple validation with optional items
existing optional items should be validated against the index matching schema. Here is an example of the data I'm trying to validate: (without ......
Read more >
Tuples, Maps, Arrays, and Options
An option is a container object that is either empty—None-- or containing a single value of some type T-- Some(value). Sometimes, instead of...
Read more >
How to create an array from existing data in NumPy
... a list of tuples, a tuple of tuples, or a tuple of lists. dtype : The data type to be applied to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found