title: Typescript writing RequiredProps generic using conditional types
body: <h3>Problem</h3>
  <p>I'm trying to define a generic <code>RequiredProps&lt;T, K&gt;</code> so that I can require a key <code>K</code> on an interface <code>T</code> to be non-nullable.</p>
  <p>For example:</p>
  <pre><code>interface User {
    id: string;
    phoneNumber?: string;
  }
  type UserWithPhoneNumber = RequiredProps&lt;User, 'phoneNumber'&gt;
  </code></pre>
  <p>Should yield a type <code>UserWithPhoneNumber</code> equivalent to <code>{ id: string; phoneNumber: string }</code></p>
  <h3>Solutions</h3>
  <p>With some trial and error I got something working:</p>
  <pre><code>type RequiredProps&lt;T, K extends keyof T&gt; = {
    [P in Exclude&lt;keyof T, K&gt;]: T[P];
  } &amp; {
    [P in K]-?: T[P];
  };
  </code></pre>
  <p>This results in an equivalent type <code>{ name: string } &amp; { phoneNumber: string }</code>, however for readability I would like it to be exactly <code>{ id: string; phoneNumber: string }</code>.</p>
  <p>Looking at the other types in <code>lib.es5.d.ts</code> I thought I could fix it using conditional types, however the following does not work:</p>
  <pre><code>type RequiredProps&lt;T, K extends keyof T&gt; = {
    [P in keyof T]: P extends K ? NonNullable&lt;T[P]&gt; : T[P];
  };
  </code></pre>
  <p>Why doesn't this work, and how can it be fixed?</p>
  <p>Here's a CodeSandbox to tinker with:
  <a href="https://codesandbox.io/s/serene-meadow-j20w1?file=/src/index.ts" rel="nofollow noreferrer">https://codesandbox.io/s/serene-meadow-j20w1?file=/src/index.ts</a></p>