Closed
Description
Bug Report
π Search Terms
inference common base type null undefined
π Version & Regression Information
- This changed between versions 4.7.3 and 4.8-beta
β― Playground Link
Playground link with relevant code
π» Code
function equal<T>(a: T, b: T) { }
let v = null!;
// Object types with common base types
type B = { foo: string }
type D = { foo: string; bar: number }
// Error in 4.8 TS can't find common type β
// 4.7 T was undefined | B
equal(v as B, v as undefined | D)
// ok T is B β
equal(v as B, v as D)
// ok T is B | undefined β
equal(v as B, v as B | undefined)
π Actual behavior
In 4.8 TypeScript can't find common base type between B
and undefined | D
. In 4.7 this used to be B | undefined
.
This also happens for literal types and their respective base types as well as for arrays as shown in the 'Other Examples' in the playground link. I didn't include the code as the bug is the same, it's just different instances we found in our code.
π Expected behavior
Typescript finds the type B | undefined
for T
as it did in 4.7.