title: How can I extract the names of all fields of a specific type from an interface in Typescript?
body: <p>Let's say I have an interface like this:</p>
  
  <pre class="lang-typescript prettyprint-override"><code>interface SomeInterface {
      field1: string;
      field2: number;
      field3: string;
      field4: SomeOtherType;
  }
  </code></pre>
  
  <p>I'd like to have a type that can extract all the keys who's values are a specific type:</p>
  
  <pre class="lang-typescript prettyprint-override"><code>type ExtractFieldsOfType&lt;Obj extends {}, Type&gt; = // implementation
  
  ExtractFieldsOfType&lt;SomeInterface, string&gt; // "field1" | "field3"
  ExtractFieldsOfType&lt;SomeInterface, number&gt; // "field2"
  ExtractFieldsOfType&lt;SomeInterface, SomeOtherType&gt; // "field4"
  </code></pre>
  
  <p>Is it possible to write something like this? I'm writing a function that operates on an object by key name, but it should only allow keys with specific values. So it'd be nice to express that through the type system.</p>