flow
flow copied to clipboard
Array.prototype.filter on non-refined nullable elements leads to unhelpful error message
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
Maybe the root cause for this is similar to that of #9015?
Yeah the root cause is the same. When we are unable to pick an overload, we might get these bad error messages.