Repository: TypeScript
Issue: Interface extension with omit produce incoherent results: Omit<C | D, 'a'>  !== Omit<C, 'a'> | Omit<D, 'a'>
Labels: Docs

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms
wrong set theory omit 
<!--
  What search terms did you use when trying to find an existing bug report?
  List them here so people in the future can find this one more easily.
-->

### 🕗 Version & Regression Information
ts-node-dev ver. 1.1.1 (using ts-node ver. 9.1.1, typescript ver. 4.1.3)
<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to
  https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

Same result also in Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies:
-->
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about it
  - ts-node-dev ver. 1.1.1 (using ts-node ver. 9.1.1, typescript ver. 4.1.3)
  - Nightly

### ⏯ Playground Link
[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.2.0-dev.20210206#code/JYOwLgpgTgZghgYwgAgEJwM7Acg3gKGWTgC5kMwpQBzAbkOQCMyQBXAW0enoF999QkWIhTosCAAoAbVhgDCyCAA9IIACYY0mbHgYIyFKiDr4+A8NHhIt46bIAiilRHWaxOgkTUHKNXvzAATwAHUW1JGXkAeShHAF4bbDt5ZAAfRIiHenwg0IzkuRj7AFlQWQBBZASo9mAwAB53TOjYgBpkAHI4DoA+bIQAexAKZGoIMABVEABrEAGAdxAq5AAKAEoyJoKi0rYMSrie1YZiuDAACwA6KDh1AfZ15CPLgFZkAH4GIlwmMgAGdr6ZAAImBPGQAHoIch6gBaWHIORwWQQTTQKADKAMMg-ZjIAHIbwgsH4Nb9IYjMaTGZzRaoYCaBLrMg1OqNcIFdpdXppZCshpbSL2LndI6HY5EU4Xa63NT3R7PN6fIjfX74wFkUF8Ig4tUEola0nk4ZgZDsOCgZbM5AANwGwDUVSOnlG4ymswWIHW9CIVPdtJA9Iw3tM2XNoG9QA)

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```ts
interface Basic {
  a: string;
  b: number;
}

interface BasicPlusC extends Basic {
  c: string;
}

interface BasicPlusD extends Basic {
  d: string;
}

type BasicPlusCOrD = BasicPlusC | BasicPlusD;

type BasicPlusCOrDMinusA = Omit<BasicPlusCOrD, 'a'>;

const getUnknown = (): BasicPlusCOrDMinusA => (
  Math.random() > .5 ?
    { b: 0, c: ""} // <-- Causes error
  : { b: 0, d: ""}
);

const getUnknownBis = (): Omit<BasicPlusC, 'a'> | Omit<BasicPlusD, 'a'> => (
  Math.random() > .5 ?
    { b: 0, c: ""}
  : { b: 0, d: ""}
);

const main = (): void => {
  getUnknown();
  getUnknownBis();
};

main();
```

### 🙁 Actual behavior

Running this code causes the following error: 
```
[INFO] 21:02:26 ts-node-dev ver. 1.1.1 (using ts-node ver. 9.1.1, typescript ver. 4.1.3)
Compilation error in /home/fabio/Projects/aalto/fullstack_open_2020_part9/part_c_patientor/backend/src/delete_me.ts
[ERROR] 21:02:27 ⨯ Unable to compile TypeScript:
src/delete_me.ts:20:13 - error TS2322: Type '{ b: number; c: string; } | { b: number; d: string; }' is not assignable to type 'Pick<BasicPlusCOrD, "b">'.
  Type '{ b: number; c: string; }' is not assignable to type 'Pick<BasicPlusCOrD, "b">'.
    Object literal may only specify known properties, and 'c' does not exist in type 'Pick<BasicPlusCOrD, "b">'.

20     { b: 0, c: ""} // <-- Causes error
               ~~~~~
```

### 🙂 Expected behavior

I would have expected both functions, `getUnknown` and `getUnknownBis` to work correctly. This is because I'm expecting the typing system to follow the same rules as set theory. In this case I have one function, `getUnknown`, whose return type structure is `({ a, b, c } | ({ a, b, d, }) \ { a }) ` which means that the resulting structure should be in the form `{ b, c } | { b, d }`.

In the other function, `getUnknownBis`, the return type structure is `({ a, b, c } \ { a }) | ({ a, b, d, }) \ { a }) ` which means that the resulting structure should be again in the form `{ b, c } | { b, d }`.

Hence I would expect both to work in the same way, but it looks like the first function is only expecting to return `{ b }`, instead of `{ b, c } | { b, d }`. This makes me think that the type inference engine is doing `{ b, c } & { b, d }` instead.