Closed
Description
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.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
fatcerberus commentedon Jun 7, 2021
That's a union type, not an intersection.
danielbartsch commentedon Jun 7, 2021
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.
[-]Intersection type not correctly narrowing down[/-][+]Union type not correctly narrowing down[/+]MartinJohns commentedon Jun 7, 2021
See: #32237 (comment)