title: Convert array of types to union of object type
body: <p>Let's say I have these types:</p>
  <pre class="lang-js prettyprint-override"><code>type StepA = // ...
  type StepB = // ...
  type StepC = // ...
  
  type Steps = [StepA, StepB, StepC]
  </code></pre>
  <p>I want to have an utility type <code>SomeUtilityType&lt;T&gt;</code> so that:</p>
  <pre class="lang-js prettyprint-override"><code>type StepsCombinations = SomeUtilityType&lt;Steps&gt;
  // type StepsCombinations =
  //   | { step: 0; value: StepA }
  //   | { step: 1; value: StepB }
  //   | { step: 2; value: StepC };
  </code></pre>
  <p>How should I define <code>SomeUtilityType&lt;T&gt;</code>?</p>
  <p><strong>Edit</strong></p>
  <p>If <code>Steps</code> is defined as an object</p>
  <pre class="lang-js prettyprint-override"><code>type Steps = {0: StepA, 1: StepB, 2: StepC}
  </code></pre>
  <p>this utility using <a href="https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types" rel="nofollow noreferrer">Distributive Conditional Types</a> would do the trick (see <a href="https://www.typescriptlang.org/play?#code/C4TwDgpgBAysFgIJQLxQERwY9AoUks8YAQqhlmAMJ4HSVXmbEl77j3EDO5A2pYgA0RBCWEMAurnaFKXAPIAjAFYQAxsHIBvAAwAuEUmEBGA5TFQATGeJUAvtLqwA9gFsIAVWABLADbfQABUOAB5cKCgANSgIAA94ADsAEx4tKF5vZLiDBIBXV0UIACcJA1yEgGsE5wB3BKg7QXCoQJj4iGSeCogQZwAzKPJu3oHI3AA+cla4xJSocqrahOaAfig0rmIDQIBuKAA3AENfXIgDSN5AiT2HCJyIfeKdxw5DLio3RUzDn2cEnjQMDcnh8-iCoTkSlUGnGQA" rel="nofollow noreferrer">playground</a>):</p>
  <pre class="lang-js prettyprint-override"><code>type SomeUtilityType&lt;
    V extends { [index: number]: unknown },
    T extends keyof V = keyof V
  &gt; = T extends unknown
    ? { step: T; value: V[T]; }
    : never;
  </code></pre>
  <p>But I would much prefer avoid defining an object with superfluous keys <code>0, 1 , 2...</code>.</p>
  <p>I think I could use the above type definition of <code>SomeUtilityType</code> if there were some way to get an union of all indexes in the array, like <code>Indexes&lt;Steps&gt; // --&gt; 0 | 1 | 2</code></p>
  <p><a href="https://www.typescriptlang.org/play?#code/C4TwDgpgBAysFgIJQLxQERwY9AoUks8YAQqhlmAMJ4HSVXmbEl77j3EDO5A2pYgA0RBCWEMAurnaFKXAPIAjAFYQAxsHIBvAAwAuEUmEBGA5TFQATGeJUAvtLqwA9gFsIAVWABLADbfQABUOAB5cKCgANSgIAA94ADsAEx4tKF5vZLiDBIBXV0UIACcJA1yEgGsE5wB3BKg7QXCoQJj4iGSeCogQZwAzKPJu3oHI3AA+cla4xJSocqrahOaAfig0rmIDQIBuKAA3AENfXIgDSN5AiT2HCJyIfeKdxw5DLio3RUzDn2cEnjQMDcnh8-iCoTkSlUGnGQA" rel="nofollow noreferrer">Playground Link</a></p>