title: Typescript enum generic mapping
body: <p>Helo Stack Community,
  I have following <code>enum</code> mapping class:</p>
  
  <pre><code>export class RestEnumMpapper&lt;T&gt; {
  
    constructor() {}
  
    getEnumAsString&lt;T&gt;(o: T, key: string | number): string {
      if (typeof key === 'string') {
        return (o as T)[(o  as T)[key]];
      } else if (typeof key === 'number') {
        return (o as T)[key];
      } else {
        throw new Error(`Unable to parse enum from ${typeof(key)}`);
      }
    }
    /* ... Rest of enum converting class code ... */
  }
  </code></pre>
  
  <p>And typical use case is following:</p>
  
  <pre><code>    export class PositionEvent {
      private static statusEnumMapper: RestEnumMpapper&lt;EventState&gt; = new RestEnumMpapper&lt;EventState&gt;();
      /* ... */
      this.status = PositionEvent.statusEnumMapper.getEnumAsString(EventState, iPos.status) as EventState;
  }
  </code></pre>
  
  <p>It works pretty well, but I'm currently linting my code and linter complains about shadowing generic type <code>T</code> in <code>RestEnumMpapper</code> class here:</p>
  
  <pre><code>export class RestEnumMpapper&lt;T&gt; {
  </code></pre>
  
  <p>and here:</p>
  
  <pre><code>getEnumAsString&lt;T&gt;(o: T, key: string | number): string {
  </code></pre>
  
  <p>Which is rational and make sense to leave generic type as class type. However, when I'm dropping <code>T</code> on function declaration on each call I'm getting following <code>TypeScritp</code> error:</p>
  
  <blockquote>
    <p>[ts] Argument of type 'typeof EventState' is not assignable to parameter of type 'EventState'.</p>
  </blockquote>
  
  <p>It can be forced to work by passing value of enum (or any other plain number) but function obviously fails when trying to resolve statement like <code>2[3]</code>.<br>
  I'd be thankful for any suggestion how to fix this? Before dropping generic type in function TypeScritp was somehow able to resolve T as object with properties and just a name of enum was sufficient to work.</p>