title: Typescript: Omit a property from all interfaces in a union, but keep the union structure
body: <p>I'm new to typescript and I have a few interfaces defined like so:</p>
  
  <pre class="lang-js prettyprint-override"><code>interface A {
    toRemove: string;
    key1: "this1";
    key2: number;
  }
  interface B {
    toRemove: string;
    key1: "this2";
    key3: string;
  }
  </code></pre>
  
  <p>And a union of both interfaces:</p>
  
  <pre class="lang-js prettyprint-override"><code>type C = A|B;
  </code></pre>
  
  <p>What I want to do is to remove the <code>toRemove</code> key from both interfaces through C, something like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>type CC = Omit&lt;A, "toRemove"&gt;|Omit&lt;B, "toRemove"&gt;;
  </code></pre>
  
  <p>But without having to omit the key from both interfaces.
  This would be ideal:</p>
  
  <pre class="lang-js prettyprint-override"><code>type CC = Omit&lt;C, "toRemove"&gt;;
  </code></pre>
  
  <p>But, unfortunately, <code>CC</code> will be of type <code>Pick&lt;A|B, "key1"&gt;</code>, where <code>key1</code> is the key present in both interfaces.</p>
  
  <p>In essence, what I'm trying to achieve is a type of "function" to transform:</p>
  
  <pre class="lang-js prettyprint-override"><code>A1|A2|...|An
  </code></pre>
  
  <p>into:</p>
  
  <pre><code>Omit&lt;A1, K keyof A1&gt;|Omit&lt;A1, K keyof A2&gt;|...|Omit&lt;An, K keyof An&gt;
  </code></pre>
  
  <p>I came across this answer <a href="https://stackoverflow.com/a/56297816/6520174">https://stackoverflow.com/a/56297816/6520174</a> and I have a feeling that part of what I need is somewhere in there, but I don't really understand what's going on in that code.</p>