Repository: TypeScript
Issue: Generic function does not accept argument of type with union and intersection
Labels: Needs Investigation

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms

<!--
  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.
-->

generic function union intersection type optional property

### 🕗 Version & Regression Information

<!-- 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

If possible, please try testing the nightly version of TS to see if it's already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=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 changed between versions 3.6.0-dev.20190723 and version 3.6.0-dev.20190724

### ⏯ Playground Link

<!--
  A link to a TypeScript Playground "Share" link which shows this behavior

  The TypeScript Workbench can be used for more complex setups, try
  https://www.typescriptlang.org/dev/bug-workbench/

  As a last resort, you can link to a repo, but these will be slower for us to investigate.
-->
[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.2.3#code/C4TwDgpgBAglC8UAUBvKBDAXBgdiKAvlAD5RoBG26ehAlFAGRlQDGA-FTQQNwCwAUAIAmEFgBt0AJ2gAzAK44WwAJYB7HFGAQAzsBgAeAApT0AWygQAHlpxDtsAHxIwJ09mOSzjWLXeu+gvwi4lLQLOq6UNoAjNgwAQLhOJHo0QiaOnpIMbQBAPQAVAUCUAWwkgDmcqYQOMBQqjKa4NAA5DCtUMr2OKr16NrayhU46ORi0MCqUC6eNVqSDU2gkFCtFJwg3ITeHQB0JWVQUAAqLWtoWLhbO0xo7JvbBJ3dUL39g8Oj45PTK20ba5PXatA78UrHSFnVbrDCPW7MB5AwgvHp9DCfEZjCaaP7nWGUZFEO5wonee4cImgw6Q2mGSSqSCSUBrcioqCmbpDHAVLoaf4XUnUG7ExGU4VPTrkOT1aQARzkymkQj5zRhgIlKL2SAATABmAAsAFZaIc8gIBAKAELpVBCrgkZiE4V0cmsTaEBJBUQSaSsCL1bQ67BWr1JFI69JaXQwbI63JQPJ5U7nRpQaTaORieqvODS+qmOSRcjQK0CIA)

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```ts
type A = ({ a: any } | { b: any }) & { c?: any };

declare function testA<Param extends A>(param: Param & A): Param;

declare const s1: A;

const a1 = testA(s1);
/**
 * Argument of type 'A' is not assignable to parameter of type '{ b: any; } & A'.
 *   Type '{ a: any; } & { c?: any; }' is not assignable to type '{ b: any; } & A'.
 *     Type '{ a: any; } & { c?: any; }' is not assignable to type '{ b: any; } & { a: any; } & { c?: any; }'.
 *       Property 'b' is missing in type '{ a: any; } & { c?: any; }' but required in type '{ b: any; }'.(2345)
 */

type B = ({ a: any } | { b: any }) & { c: any };

declare const s2: B;

const a2 = testA(s2); // Type of result is A but must be B

```

### 🙁 Actual behavior

<!-- What happened, and why it was wrong -->
The line `const a1 = testA(s1);` gives an error: 
```
Argument of type 'A' is not assignable to parameter of type '{ b: any; } & A'.
  Type '{ a: any; } & { c?: any; }' is not assignable to type '{ b: any; } & A'.
    Type '{ a: any; } & { c?: any; }' is not assignable to type '{ b: any; } & { a: any; } & { c?: any; }'.
      Property 'b' is missing in type '{ a: any; } & { c?: any; }' but required in type '{ b: any; }'.(2345)
```

In the line `const a2 = testA(s2);` the typescript compiler infers the constanta `a2` has type `A`

### 🙂 Expected behavior

<!-- What you expected to happen instead, and why -->
The variable `s1` has the type `A` that means `function testA<Param extends A>(param: Param & A): Param` accepts `s1`. The parameter type `Param` is instantiated to `A`.

The constant `a2` has the type `B` since the parameter `s2` has the type `B`.

It was a normal behavior up to [version 3.6.0-dev.20190723](https://www.npmjs.com/package/typescript/v/3.6.0-dev.20190723). Since then it leads to errors.