facebook / facebook/flow

Flow can't seem to choose between union types

Open
#5,873 2 comments 0 reactions 0 assignees View on GitHub
Typing: refinements Typing: tuple
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

[try flow](https://flow.org/try/#0CYUwxgNghgTiAEAzArgOzAFwJYHtXwHMRUAKASgC54BtAURhhxgBp5VkIIBdeAHxvadW7ALYAjEDC4BuAFCyweAM4Yaklm2TjJPALyFi5ObKyJ4JAITqy8AN6yAkCVESYVF5LKyAvrKA)

```js
declare function gen(): [Error, null] | [null, number];

const [err, number] = gen();

if (!err) {
(number: number)
}
```

that last cast throws an error that `number` can be `null` even though the `if` statement should force `(err: null)` and `(number: number)`

Any suggestions on how to re-write this would be appreciated!

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.