js-schema
js-schema copied to clipboard
heterogeneous array
Is there a way to specify an array with items having different types? E.g. for data
['square' 1 1 4 4]
['circle' 1 1 3]
the schema should match either array of string 'square' + four numbers, or array of string 'circle' + three numbers. It should not match array of 'circle' + four numbers, or 'square' with three.
I haven't found a recursive Array declaration, only Array (match class only), Array.of (match homogeneous elements), and Array.like (exact match).
:+1: :+1: :+1:
it sounds like you're looking for typed tuples. i need something similar - union types. eg.
{
foo: Array.of(String),
bar: Array.of(Number),
baz: Array.of(String.or(Number))
}