Optional array / tuple elements
See original GitHub issueI 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:
- Created 5 years ago
- Reactions:1
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same thing happens for me: When using type Array<SomeInterface | null>, typescript-json-schema ignores the null type in the “items” property.
Same issue here. Undefined is missing.
something?: number | undefined;
in an array becomes{"type":"object","properties":{"something":{"type":"number"}
and undefined just goes puff!