title: Generic function to convert string to typescript enum
body: <p>I found <a href="https://stackoverflow.com/a/42623905/2517147">this great answer</a> about how to convert a string to a typescript enum.  Based on that I have written this function</p>
  
  <pre><code>enum Color { Red='red', Green='green' }
  
  function mapColorString(strColor: string): Color {
    const colorKey = strColor as keyof typeof Color
    return Color[colorKey]
  }
  </code></pre>
  
  <p>But now when I try to make it generic, </p>
  
  <pre><code>function getEnumFromString&lt;T&gt;(str: string): T {
    const enumKey = str as keyof T
    return T[enumKey]
  }
  </code></pre>
  
  <p>I get the error in the return statement: <code>'T' only refers to a type, but is being used as a value here.</code></p>
  
  <p>I want to make this generic because I have a number of enums that I need to generate based on their string values, and I would like to not have a separate method for every one.</p>