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

Union type not correctly narrowing down #44479

Closed
danielbartsch opened this issue Jun 7, 2021 · 3 comments
Closed

Union type not correctly narrowing down #44479

danielbartsch opened this issue Jun 7, 2021 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@danielbartsch
Copy link

danielbartsch commented Jun 7, 2021

Bug Report

🔎 Search Terms

union narrowing wrong

🕗 Version & Regression Information

in 3.7.5. still there in 4.3.2

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "bugs that aren't bugs"
  • I was unable to test this on prior versions because prior versions don't support ??

⏯ Playground Link

Playground link with relevant code

💻 Code

type A = { a: number, b: string }[]
type B = { a: number }[]

declare var c: A | B | undefined;

const d = c ?? []

// d is now just B, but should be A | B

🙁 Actual behavior

Type inference excludes a part in the intersection type.

🙂 Expected behavior

Type inference should just exclude undefined, because the ?? operator was used on the variable.

@fatcerberus
Copy link

That's a union type, not an intersection.

@danielbartsch
Copy link
Author

whoops. You're right. With that correction, I was able to find related issues:
#44401
#43825
#43667

which are almost the same, but not quite.

@danielbartsch danielbartsch changed the title Intersection type not correctly narrowing down Union type not correctly narrowing down Jun 7, 2021
@MartinJohns
Copy link
Contributor

See: #32237 (comment)

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants