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
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.
TypeScript Version: 3.3.3
Search Terms:
Union types overlapping
Code
Expected behavior:
No type errors exist, because there is an interface which would accept 'blue'.
Actual behavior:
An error is thrown:
Playground Link:
Link to the playground example
The text was updated successfully, but these errors were encountered: