facebook / facebook/flow

Support extra `filter` and `every` type refinement

Open
#7,793 3 comments 3 reactions 0 assignees View on GitHub
feature request Typing: refinements
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Flow version: 0.100.0

The attached tryflow link shows some examples of `every` not being used for type refinement.
I'd expect that Flow would see those refinements and not throw any errors.
The same applies for `.filter(i => i != null)`.

Here is the same code inline for easier inspection before going to the tryflow link:
```js
const a = [3, null];

if (a.every(Boolean)) {
(a: Array); // expected no error
}

if (a.every(b => b != null)) {
(a: Array); // expected no error
}

(a.filter(b => b != null): Array); // expected no error

// Note that this pattern is supported
(a.filter(Boolean): Array);
```

https://flow.org/try/#0MYewdgzgLgBAhjAvDA2gZgDQzAVwDZ4C6A3AFCkCWAZjABRwB0ApgG5MBOAnrQEIgh4mcMAEoRMAN6kYMunABcMAILt2cTgB5cAWwBGHAHwjiMAPSmYTAB4AHJsChMAJthCXVIdqQC+5anOY2LlpdJAMYUIBCZFwCMUlpWXpFFTVNHX12IxNzS1t7RxcwNw52Tx9yegYqCjxHdhCwiJho7Hw8ERTVdS0cPUNjMwtrOwdnV3cyr1JcgDkQRxgoAAs4WBWKCBgbNfqwGE2YCBwbG09C0iqauo5efkFhTuVu9L7M7NIgA

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.