Skip to content

Support extra filter and every type refinement #7793

@fabiomcosta

Description

@fabiomcosta

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:

const a = [3, null];

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

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

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

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions