Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flex-tjon opened this issue Mar 6, 2023 · 2 comments
Labels

Comments

@flex-tjon
Copy link

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
@flex-tjon
Copy link
Author

Maybe the root cause for this is similar to that of #9015?

@SamChou19815
Copy link
Contributor

Yeah the root cause is the same. When we are unable to pick an overload, we might get these bad error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants