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 type is not compatible to second union type, even with full overlap. #30170
interfaceBlue{color: 'blue'}interfaceYellow{color?: 'yellow',}functiondraw(val: Blue|Yellow){}functiondrawWithColor(currentColor: 'blue'|'yellow'|undefined){// The following line throws the type error: Type '"blue"' is not assignable to type '"yellow"'.returndraw({color: currentColor});}
Expected behavior:
No type errors exist, because there is an interface which would accept 'blue'.
Actual behavior:
An error is thrown:
Argument of type '{ color: "blue" | "yellow"; }' is not assignable to parameter of type 'Blue | Yellow'.
Type '{ color: "blue" | "yellow"; }' is not assignable to type 'Yellow'.
Types of property 'color' are incompatible.
Type '"blue" | "yellow"' is not assignable to type '"yellow"'.
Type '"blue"' is not assignable to type '"yellow"'.
It might be the case that a literal with type { x : A | B } is assignable to { x: A } | { x: B }, but this does not hold when you have more properties. TypeScript wont special-case for single property objects.
Activity
jack-williams commentedon Mar 1, 2019
It might be the case that a literal with type
{ x : A | B }is assignable to{ x: A } | { x: B }, but this does not hold when you have more properties. TypeScript wont special-case for single property objects.RyanCavanaugh commentedon Mar 1, 2019
#8289 / #12052 / #18421