title: How to define generic function rejecting key from object in Typescript?
body: <p>I'm trying to define a utility function to clean up objects of specific keys.</p>
  
  <pre><code>/**
   * Strip all the __typenames from the payload.
   */
  interface WithTypename {
    __typename?: string;
  };
  
  type Omit&lt;T, K extends keyof T&gt; = Pick&lt;T, Exclude&lt;keyof T, K&gt;&gt;;
  
  const omitTypename = &lt;T extends WithTypename&gt;({ __typename, ...rest }: T): Omit&lt;T, '__typename'&gt; =&gt; ({ ...rest });
  </code></pre>
  
  <p>But compiler complains on the function parameters that <code>{ __typename, ...rest }</code>. <em>Rest types may only be created from object types.</em></p>