title: How to declare types for an array of objects whose properties are interdependent?
body: <p>I would like to declare type for object (<code>root</code>), that contains nested array of objects (<code>values</code>), where each object has properties <code>one</code> (any type) and <code>all</code> (array of <code>one</code>'s type).</p>
  <p>Bellow is my attempt to do it, however I don't know how to obtain types of <code>one</code>property, so there is just <code>Value&lt;any&gt;</code>:</p>
  <pre class="lang-js prettyprint-override"><code>type Value&lt;T&gt; = { one: T, all: T[] }
  type Root = { values: Value&lt;any&gt;[] }
  
  const root: Root = {
      values: [
          { one: 1, all: 5 }, // Should be error, 'all' should be an array of numbers.
          { one: true, all: [5] }, // Should be error, 'all' should be array of booleans.
          { one: 'a', all: ['a', 'b', 'c'] }, // Ok.
          { one: true, all: [false, true, true] } // Ok.
      ]
  }
  </code></pre>
  <p>Is there any way how to do that? Here is <a href="https://www.typescriptlang.org/play?#code/C4TwDgpgBAaghgGwK4QDwBUB8UC8UDeUA9gHYQBcU6ANFIgpegNoC6UAvgFCiRQBKRIsFwEoAN0QoAzpXjI0cEiEysOnTgGNSU4QCdBwSgKEj8nKBfGSIMqE3OXHhUhSgBGWvUoBWDrQD0-lAAorr6urQA5PSRUFIAFkRICAAmUABG0Ip0YXAgxABmUCRIALaZulIAdA6OFs5klMC6KJ4IDHbebOwBQaHhUTFxiclpmTm6eYUZgggQitW1dQ2u0ZFtHUxrUenrUJEakd29UADyANY1dZYrTS0QG5RMBYhSD1DNrR-33VCBZ5clixOOwgA" rel="nofollow noreferrer">example</a>. It would be amazing, if it could be without naming all possible combinations of types like:</p>
  <pre><code>type Value = { one: string, all: string[] } | { one: number, all: number[] } | { one: boolean, all: boolean[] }
  </code></pre>
  <p>because it should be applicable to any type.</p>