title: How to properly use spread opeartor in Javascript/Typescript
body: <p>I have two objects with two different types, I want to use one object to assign another.</p>
  <pre class="lang-js prettyprint-override"><code>interface From {
    type: string;
    timestamp: number;
    aid?: string;
    bid?: string;
    cid?: string;
    did?: string;
    eid?: string;
    fid?: string;
    gid?: string;
  }
  
  interface To {
    fromSocketID: string;
    type: string;
    timestamp: number;
    aid?: string;
    bid?: string;
    cid?: string;
    did?: string;
    eid?: string;
    fid?: string;
  }
  
  const from: From = {
    type: &quot;aaa&quot;,
    timestamp: 1231231231,
    gid: &quot;ddd&quot;
  };
  
  // Method1
  const to1: To = {
    fromSocketID: &quot;temp&quot;,
    type: from.type,
    timestamp: from.timestamp
  };
  if (from.aid) {
    to1.aid = from.aid
  }
  if (from.bid) {
    to1.bid = from.bid;
  }
  if (from.cid) {
    to1.cid = from.cid;
  }
  // ...three more if statements
  
  // Method2
  const to2: To = {
    fromSocketID: &quot;temp&quot;,
    ...from
  }
  // @ts-ignore
  delete to2.gid;
  </code></pre>
  <p><code>interface To</code> has a <code>fromSocketID</code> which <code>From</code> doesn't, and <code>To</code> lacks a <code>gid</code> property. In my real work scenario, I use Method1. I tried Method2, but i had to use <code>ts-ignore</code>. I wonder if there is a better solution.</p>