You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Union doesn't merge objects properties' type #8289
Actual behavior:
TypeScript reports this error for the const c: A | B = { x: 1 || "a" }; statement:
Type '{ x: number | string; }' is not assignable to type 'A | B'.
Type '{ x: number | string; }' is not assignable to type 'B'.
Types of property 'x' are incompatible.
Type 'number | string' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
I should add that we've gotten this request around single-property types a bunch. It turns out to be very difficult to detect all of these cases properly in the compiler.
Activity
[-]Union doesn't merge object properties' type[/-][+]Union doesn't merge objects properties' type[/+]mhegazy commentedon Apr 25, 2016
{ x: number | string };is neitherAnorB. it becomes easier to see that with more than one property, e.g.RyanCavanaugh commentedon Apr 25, 2016
I should add that we've gotten this request around single-property types a bunch. It turns out to be very difficult to detect all of these cases properly in the compiler.
nicolo-ribaudo commentedon Apr 26, 2016
Mohamed Hegazy (@mhegazy) Thank you, now I see why the current behavior is correct