Generic type to get enum keys as union string in typescript? : <p>Consider the following typescript enum:</p>

<pre><code>enum MyEnum { A, B, C };
</code></pre>

<p>If I want another type that is the unioned strings of the keys of that enum, I can do the following:</p>

<pre><code>type MyEnumKeysAsStrings = keyof typeof MyEnum;  // "A" | "B" | "C"
</code></pre>

<p>This is very useful.</p>

<p>Now I want to create a generic type that operates universally on enums in this way, so that I can instead say:</p>

<pre><code>type MyEnumKeysAsStrings = AnyEnumKeysAsStrings&lt;MyEnum&gt;;
</code></pre>

<p>I imagine the correct syntax for that would be:</p>

<pre><code>type AnyEnumKeysAsStrings&lt;TEnum&gt; = keyof typeof TEnum; // TS Error: 'TEnum' only refers to a type, but is being used as a value here.
</code></pre>

<p>But that generates a compile error: "'TEnum' only refers to a type, but is being used as a value here."</p>

<p>This is unexpected and sad.  I can incompletely work around it the following way by dropping the typeof from the right side of the declaration of the generic, and adding it to the type parameter in the declaration of the specific type:</p>

<pre><code>type AnyEnumAsUntypedKeys&lt;TEnum&gt; = keyof TEnum;
type MyEnumKeysAsStrings = AnyEnumAsUntypedKeys&lt;typeof MyEnum&gt;; // works, but not kind to consumer.  Ick.
</code></pre>

<p>I don't like this workaround though, because it means the consumer has to remember to do this icky specifying of typeof on the generic.</p>

<p>Is there any syntax that will allow me to specify the generic type as I initially want, to be kind to the consumer?</p>
