title: How to define type of an object to accept only keys from enum?
body: <p>I have an enum:</p>
  
  <pre><code>enum MyEnum {
      One,
      Two,
      Three
  }
  </code></pre>
  
  <p>Then I have a method of React Component which should return an object, whose keys can only be string keys of MyEnum (meaning, so far: One, Two, Three):</p>
  
  <pre><code>myFunction = (someValue: {}[]): {} =&gt; {
      return someValue.reduce((res, v, i) =&gt; {
           res[v.name].push(v)
           return res
      }, {})
  }
  </code></pre>
  
  <p><strong>Question:</strong> How can I dynamically define the type of the return value of this function to be an object, whose keys can only be string keys of MyEnum? </p>
  
  <p>Right now there are only 3 of them, but if I add another one to the enum, the type of the return value of myFunction should also be updated.</p>
  
  <p><strong>Update 1:</strong></p>
  
  <p>Tried assigning <code>Record&lt;keyof typeof MyEnum, any&gt;</code> as a return value:</p>
  
  <pre><code>myMethod = (someValue: {}[]): Record&lt;keyof typeof MyEnum, any&gt; =&gt; {
      return someValue.reduce((res: any, v: SomeInterface) =&gt; {
           res[v.name].push(v)
           return res
      }, {})
  }
  </code></pre>
  
  <p>This does not throw any errors, but if I assign the return value of reduce to a variable and then add another property on it (whose key is not MyEnum key), there would be no error, which is not what I seek:</p>
  
  <pre><code>myMethod = (someValue: {}[]): Record&lt;keyof typeof MyEnum, any&gt; =&gt; {
      let someVar = someValue.reduce((res: any, v: SomeInterface) =&gt; {
           res[v.name].push(v)
           return res
      }, {})
      someVar.keyName = 'value'
      return someVar
  }
  </code></pre>