title: Typescript: How to take subset of attributes from an object?
body: <p>Example:</p>
  
  <pre><code>type t = {
    a1: boolean;
    a2: number;
    a3: string;
  };
  
  const o1 = {
    a1: true,
    a2: 1,
    a3: 'blah',
    a4: false,
    a5: 'blah blah'
  }
  
  const o2: t = o1 as t;  // this doesn't work as I expected
  </code></pre>
  
  <p>How to set o2 dynamically to take only o1's attributes which fit type t?</p>
  
  <p>I.e., keep the attributes that fit and discard the rest. In this case with a result equivalent to</p>
  
  <pre><code>const o2: t = {
    a1: o1.a1,
    a2: o1.a2,
    a3: o1.a3
  }
  </code></pre>
  
  <p>except done dynamically as t may change.</p>