facebook / facebook/flow

Feature request: refining multiple disjoint unions

Open
#5,948 4 comments 0 reactions 0 assignees View on GitHub
feature request
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Hello Flow team!

[[Flow try link](https://flow.org/try/#0PTAEAEDMBsHsHcBQiAuBPADgU1AQVALygDeiooKAhgOYBcoA5JQwDSIC+A3KpjgEKESZCjXoMARqw7d02UADFYsQfgA+oPt0QBjWADsAzilDjKAJ0EAKAB71FsFqDR2lASkIA+IeQCWkUDYAdFTUhARETAzupOTkZlgoAK5meozWoD4GoMzc5OygWNAGOH4BaME0YRHM0cJxCcmpDGgZ6TnC+YXFGf5BIVWMkqAAZMNOFaHhEZK1saDxSSmDsCgAFtnxJgy5oJ1FODGxNvRYALYY6K475JbOBeeXO+wcQA)]

```jsx
// @flow

type A = {
tag: 'a',
};
type B = {
tag: 'b',
};
type Foo = A | B;

const bar = (x: Foo, y: Foo) => {
if (x.tag === 'a') {
return 'x is a';
} else if (y.tag === 'a') {
return 'y ix a';
} else if (x.tag === 'b' && y.tag === 'b') {
return 'both are b';
} else {
(x: empty);
(y: empty);
}
}
```

All cases are covered by the first three branches in the if/else, so the `empty` assertions in the last branch should be correct. As an example, Flow correctly identifies this when we assert that `x` and `y` are both `B` ([Flow try link](https://flow.org/try/#0PTAEAEDMBsHsHcBQiAuBPADgU1AQVALygDeiooKAhgOYBcoA5JQwDSIC+A3KpjgEKESZCjXoMARqw7d02UADFYsQfgA+oPt0QBjWADsAzilDjKAJ0EAKAB71FsFqDR2lASkIA+IeQCWkUDYAdFTUhARETAzupOTkZlgoAK5meozWoD4GoMzc5OygWNAGOH4BaME0YRHM0cJxCcmpDGgZ6TnC+YXF3rE29Hyuub3OGoMdHEA)).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.