Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: intersection of a generic type bound to a discriminated union with one of the union constituencies reduces to never #38549

Closed
Igorbek opened this issue May 13, 2020 · 3 comments · Fixed by #38565
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@Igorbek
Copy link
Contributor

Igorbek commented May 13, 2020

TypeScript Version: 3.9.2

Search Terms: Generic union intersection

Code

interface A {
  kind: "A";
  a: number;
}

interface B {
  kind: "B";
  b: number;
}

declare const shouldBeB: (A | B) & B;
const b: B = shouldBeB; // works

function inGeneric<T extends A | B>(alsoShouldBeB: T & B) {
  const b: B = alsoShouldBeB;
  //    ~ TS2739: Type 'T & B' is missing the following properties from type 'B': kind, b
}

Expected behavior:

No errors (were no errors on 3.8)

Actual behavior:

TS2739: Type 'T & B' is missing the following properties from type 'B': kind, b

Playground Link: link

Related Issues:

It seems to be related to #36696

@Igorbek Igorbek changed the title Regression: intersection of a generic type bound to a union with one of the union constituencies reduces to never Regression: intersection of a generic type bound to a discriminated union with one of the union constituencies reduces to never May 13, 2020
@ahejlsberg ahejlsberg self-assigned this May 13, 2020
@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label May 13, 2020
@ahejlsberg
Copy link
Member

This is basically a duplicate of #38542, but the repro is simpler here.

@Igorbek
Copy link
Contributor Author

Igorbek commented May 13, 2020

This is basically a duplicate of #38542, but the repro is simpler here.

I saw it and couldn't recognize whether it was the same issue or not.

@HitalloExiled
Copy link

I had some similar problems at the intersection of properties with different values:

type T01 = { a: "a" } & { a: "b" }; // never, expects { a: "a"|"b" }
type T02 = { a: "a" } & { a: null }; // never, expects { a: "a"|null }
type T04 = { a: "a" } & { a: undefined }; // never, expects { a: "a"|undefined }
type T03 = { a: string } & { a: null }; // never, expects { a: string|null }
type T05 = { a: string } & { a: undefined }; // never, expects { a: string|undefined }
type T06 = { a?: string } & { a: undefined }; // { a: undefined }, { a?: string|undefined }

Does this issue cover that too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants