title: TypeScript: Define a union type from an array of strings
body: <p>I can't be the first person coming across this, but my searches have not turned up any useful leads yet. Would greatly appreciate some expert TypeScript advice.</p>
  
  <p>Say I have an array:</p>
  
  <pre><code>const fruits = ["Apple", "Orange", "Pear"];
  </code></pre>
  
  <p>and I want to define an object mapping each fruit to some fun facts about it:</p>
  
  <pre><code>interface Facts {
      color: string,
      typicalWeight: number
  }
  
  const fruitFacts: { [key: members of fruits]: Facts } = {
      "Apple": { color: "green", typicalWeight: 150 }
      //
  }
  </code></pre>
  
  <p>How do I do that <code>[key: members of fruits]</code> part?</p>
  
  <p>Bonus: How do I enforce that my <code>fruitFacts</code> object exhaust all the keys derived from the array as well, so that it specifies facts for Apples, Oranges, and Pears in the example above. </p>