title: Typescript: How to extract only the optional keys from a type?
body: <p>Let's say I have a type like this:</p>
  
  <pre><code>type User = {
    uid: string,
    displayName?: string,
    bestFriend?: string,
  }
  </code></pre>
  
  <p>Is it possible to extract the optional properties from my User type using a
  mapped type of some kind? I'm looking for how to define the
  <code>OptioanlProperties&lt;T&gt;</code> type below.</p>
  
  <pre><code>type OptionalUserProperties = OptionalProperties&lt;User&gt;
  // type OptionalUserProperties = "displayName" | "bestFriend"
  </code></pre>
  
  <p>My use-case is to compute an <code>UpdateOf&lt;User&gt;</code> type that permits specific
  "operation" values, like <code>DeleteProperty</code> to be assigned to keys that are optional in the base type.</p>
  
  <pre><code>export type UpdateOf&lt;T&gt; =
    // optional fields may be their own type, or the special DeleteProperty type.
    { [P in OptionalProperties&lt;T&gt;]?: T[P] | DeleteProperty } &amp;
    // required fields may be changed, but cannot be deleted.
    { [P in Diff&lt;keyof T, OptionalProperties&lt;T&gt;&gt;]?: T[P] }
  </code></pre>