Repository: TypeScript
Issue: Generics return type of function reported not assignable.
Labels: Bug

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms

return value, typescript, generics

### 🕗 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.5.1 and 3.6.3

### ⏯ 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.
-->
https://www.typescriptlang.org/play?ts=3.6.3#code/C4TwDgpgBAKuEGECGBnCBBAPOgfFAvFAN5QAmSwSAXFOlAL4DcAUKJLPMmgEKbcFQUwAE4BLAHYBzPIRLlKAfhrdGUAMYB7UhBpCxU1U1bwOkLhl7oANFH6E9E6QLhnUGbHgA+pxG97ccFmY1ABtUFCgAZQhhADdRNWgiZihUqEkIYH8BBykcAApNbV0RRxt5JCVbAEoaF18ePjxktNb1DXEhKGEIFABXEOA6zj8mgTkKJBsi6CM2tJ7gPuFxbt6B4BZW+mYUtIzgLFx8ipp0Wp9zI+a9+cXl1YnKBi20nduoADM+8TUARnyF3qV14JFEpBo4j6AFsAEYxBg3eape4rKDAAAWohQADoDtx8gByP4AJgAzH9CdVXql3q1vr8SYDhq40OhQVBwZCYfDhIjiB9WppOsA1sBYkgQgJMdi8ZkCcTyZTqYKFpkHmKJSEaQxdvSfmoyczLm52ZgwRCoFC4Qj6DZck4WsjUasZbj8UTSRTCTZCQAWACsADYqTqdvQgA

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```ts
type TypeCaseA<A> = { data: A };
type TypeCaseB<B = string> = { data?: B; code: string; };
type TypeCaseAB<A, B = string> = TypeCaseA<A> | TypeCaseB<B>;

class Service {
    getB<B = string>(code: string, data?: B): TypeCaseB<B> {
        const result: TypeCaseB<B> = { data, code };
        return result;
    }

    getA<A>(data: A): TypeCaseA<A> {
        return { data };
    }

    func1(): TypeCaseAB<{ id: number }> {
        /* The following line is blamed with:
          Type 'TypeCaseB<string | { id: number; }>' is not assignable to type 'TypeCaseAB<{ id: number; }, string>'.
            Type 'TypeCaseB<string | { id: number; }>' is not assignable to type 'TypeCaseB<string>'.
              Type 'string | { id: number; }' is not assignable to type 'string'.
                Type '{ id: number; }' is not assignable to type 'string'.
         */
        return this.getB('1231');
    }

    func2(): TypeCaseAB<{ id: number }> {
        const retval = this.getB('1231');
        return retval;
    }

    func3(): TypeCaseAB<{ id: number }, string> {
        return this.getB('1231', '456');
    }
}
```

### 🙁 Actual behavior

<!-- What happened, and why it was wrong -->
`func1` is tested with the following error:
```
          Type 'TypeCaseB<string | { id: number; }>' is not assignable to type 'TypeCaseAB<{ id: number; }, string>'.
            Type 'TypeCaseB<string | { id: number; }>' is not assignable to type 'TypeCaseB<string>'.
              Type 'string | { id: number; }' is not assignable to type 'string'.
                Type '{ id: number; }' is not assignable to type 'string'.
```

There should be no difference from `func2` which is tested correct.

### 🙂 Expected behavior

<!-- What you expected to happen instead, and why -->
No error reported.