Skip to content

Array.prototype.filter on non-refined nullable elements leads to unhelpful error message #9019

Open
@flex-tjon

Description

@flex-tjon

Flow version: 0.201.0

Expected behavior

Flow points out that documents is an array of nullable elements and filteredDocuments is an array of non-null elements, which requires a filter/refinement in order to satisfy that type constraint

Actual behavior

Flow emits an error that looks like:

56:         .filter((document) => {
             ^ Cannot call `documents.filter(...).filter` because property `name` is missing in function [1] but exists in statics of `Boolean` [2]. [incompatible-call]
References:
56:         .filter((document) => {
                    ^ [1]
[LIB] ..//flow/v0.201.0/flowlib/core.js:367: declare class Boolean {

This seems related to filter being an overloaded method type to support both .filter(Boolean) and the usual callback definitions, but this error makes it difficult to find the root cause of the issue. Annotating the filter callback params doesn't seem to fix that either.

  • Link to Try-Flow or Github repo: Try Flow

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions