title: Get Keys of a Type using Keyof Type Operator
body: <p>I have this Identity interface</p>
  <pre><code>export interface Identity {
      username: string;
      name: string;
      surname: string;
      roles: string[];
  }
  </code></pre>
  <p>and I want to get an array of Strings at runtime with all its keys.</p>
  <pre><code>const keys: string[] = [&quot;username&quot;, &quot;name&quot;, &quot;surname&quot;, &quot;roles&quot;];
  </code></pre>
  <p>If it were a class, it would have been easy enough using the constructor (as suggested <a href="https://stackoverflow.com/a/59806829/8737144">here</a>).</p>
  <pre><code>class Identity {
      constructor(
          readonly username?: string,
          readonly name?: string,
          readonly surname?: string,
          readonly roles?: string[]
      ) {}
  }
  
  const properties: string[] = Object.keys(new Identity());
  </code></pre>
  <p>I have found other similar questions, some about the <a href="https://www.typescriptlang.org/docs/handbook/2/keyof-types.html" rel="nofollow noreferrer">Keyof Type Operator</a>, with the most relevant being:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/43909566/get-keys-of-a-typescript-interface-as-array-of-strings">Get keys of a Typescript interface as array of strings</a></li>
  <li><a href="https://stackoverflow.com/questions/47901360/typescript-keyof-return-array-of-strings">Typescript keyof return array of strings</a></li>
  <li><a href="https://stackoverflow.com/questions/45612643/typescript-spread-interface-keys-as-union-of-strings">Typescript spread `interface` keys as union of strings</a></li>
  </ul>
  <p>In the above questions, however, the result of keyof is only used as a type/value constraint.
  What about how to get the keys as a String array using the keyof operator? Is this not possible from an Interface definition or for classes too?</p>
  <p><strong>TypeScript Custom Transformer</strong></p>
  <p>This <a href="https://github.com/kimamula/ts-transformer-keys" rel="nofollow noreferrer">project</a>, a custom transformer, does exactly what I'm looking for: get the keys of a given Type.</p>
  <p>I'm wondering if there is an easier way, possibly using only the keyof operator to get the same result.</p>