js-schema icon indicating copy to clipboard operation
js-schema copied to clipboard

heterogeneous array

Open acthp opened this issue 9 years ago • 1 comments

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).

acthp avatar May 17 '15 19:05 acthp

:+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))
}

bcherny avatar Oct 19 '15 19:10 bcherny