Union type inferring is somewhat incomplete
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
I've reproduced the bug using the online Flow type checker. Please refer to the following code:
```js
type TestType = {
type: "a",
a: number
} | {
type: "b",
b: number
};
const test = (a: TestType, b: TestType) => {
if (a.type === "a" && a.type === b.type) {
return b.a;
}
return 0;
}
```
This gives me an error:
```
11: return b.a;
^ Cannot get `b.a` because property `a` is missing in object type [1].
References:
9: const test = (a: TestType, b: TestType) => {
^ [1]
```
However, this gives no errors:
```js
type TestType = {
type: "a",
a: number
} | {
type: "b",
b: number
};
const test = (a: TestType, b: TestType) => {
if (a.type === "a" && b.type === "a" && a.type === b.type) {
return b.a;
}
return 0;
}
```
It should be inferred that because `a.type === "a" && a.type === b.type`, therefore `b.type === "a"`.
Contributor guide
Assessment
This issue has not been assessed yet.