Union type restrictions don't work when used within other objects
Open
Typing: unions/intersections
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Easiest to explain with code:
```jsx
type MyType = "A" | "B"
type WrappedType = {
myType : MyType
}
const x : MyType = "A";
const y : WrappedType = {
myType : x
}
if (x === 'C') { //Error: string literal `C`. This type is incompatible with string enum
//...
}
if (y.myType === 'C') { //No error, even though this is just as invalid as the above
// And from here `y` is treated as an `Object` type, meaning that any property access is valid:
const z = y.x * 3; // No error, even though this is obviously invalid
}
```
It seems to me that the behavior of the second conditional is a bug. Or is there any reason why flow doesn't detect the errors here?
Contributor guide
Assessment
This issue has not been assessed yet.