title: Conditionally desctructure in union arguments
body: <pre><code>export type IVertex = {
    id: string
    name: string
  }
  
  export type IEdge = {
    source: string
    target: string
  }
  </code></pre>
  <p>type.ts</p>
  <pre><code>  formatVertices (nodes: Array&lt;IVertex&gt;) {
      return nodes.map(node =&gt; {
        const { name, ...rest } = node
        return {
          data: { ...rest }
        }
      })
    }
  
    formatEdges (nodes: Array&lt;IEdge&gt;) {
      return nodes.map(node =&gt; ({ data: node }))
    }
  </code></pre>
  <p>How to refactor these methods into one?</p>
  <p>I want to exclude <code>name</code> field in <code>IVertex</code> node. And I've tried adding <code>name</code> field in both nodes and destructure other fields, but still there's a type error.</p>
  <pre><code>formatNodes (nodes: Array&lt;IVertex|IEdge&gt;) {
      return nodes.map(node =&gt; {
        const { name, ...rest } = { node, name: '' }
        return {
          data: { ...rest }
        }
      })
    }
  </code></pre>
  <p>Sample: <a href="https://www.typescriptlang.org/play?#code/LAKFAJwUwDwBwPYCcAu4UE85XASQGpSqzgC84A3hJOAJYAmAXOAM4pK0B2A5tZJwEMAtlGZsOPagF9Q1WIlTosOXAFF63HOSogarBAFckAY1Gt2XXrpooBSTSjEXJ1mWGvGEnNuABuRFFpTFmYCANgAbQBdMnAIvkoEyAZmAHIAQVSAGiTwQRE0gCkBYwBrVISpLJ09ZKZwVIAhbNz8s1SAJQQRCutIN0go2Q8vHygNKBC8dU1o2Pi%20xMXIFkMTdsyc5fQ7BzTmyq29GtrVo1M0gGEW7dt7KEcGgBFevQHwIfdwT280ADNkEIBChCKggpNYgAKTgIeiTZjpJBIAQYAA8YWIMAAfABKJZ6JAPIycPKwyYAOiBcGhZLIWPxtR%20PgoeWEUCy4HJXMJPiksRhcNyhJQxIZtXA9GBAmYLK55J5aHeb0qOOkw0gTP%20gOBMwh5BpcKmiORaLUE1xYvAwtFAopVINWnpkJZktszFt4CkONVrnV31GWqQQJQADlafrbUakSj0aCULAAD5mzQWk6Qa1IEmRykCake0j0tM0TWUVkiDlyhWe-lkoVEzOWvSu6WlyuTRW5JWen39IA" rel="nofollow noreferrer">demo</a></p>