title: Map Typescript Enum
body: <p>How would I map a typescript enum? For example, with strings you can do this:</p>
  
  <pre><code>let arr = [ 'Hello', 'Goodbye' ];
  
  arr.map(v =&gt; {
    if (v === 'Hello') {
      return ':)';
    } else if (v === 'Goodbye') {
      return ':(';
    }
  ); // [ ':)', ':(' ]
  </code></pre>
  
  <p>This, of course, doesn't work with enums:</p>
  
  <pre><code>enum MyEnum { Hello, Goodbye };
  
  MyEnum.map(v =&gt; {
    if (v === MyEnum.Hello) {
      return ':)';
    } else if (v === MyEnum.Goodbye) {
      return ':(';
    }
  }); // does not work
  </code></pre>
  
  <p>Ideally, I'd like to do this in a generalized way so I can simply take any enum I have and put it through a map function <strong>while preserving type information</strong>. Usage might look something like this:</p>
  
  <pre><code>map(MyEnum, v =&gt; {
    if (v === MyEnum.Hello) {
      return ':)';
    } else if (v === MyEnum.Goodbye) {
      return ':(';
    }
  }); // [ ':)', ':(' ]
  </code></pre>
  
  <p>I've been fiddling around with getting a function that does this for me but keep having issues getting the generics just right.</p>