facebook / facebook/flow

`instanceof Function` incorrectly refines to a callable

Open
#6,120 0 comments 2 reactions 0 assignees View on GitHub
Typing: refinements
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

The code
```
const f = Object.create(Function);
if (f instanceof Function) {
f();
}
```
should result in a Flow error since `f` is not actually callable (executing the code results in a `TypeError: f is not a function`).

In other words: After the type refinement `typeof f === 'function'` it's OK to assume `f` is callable, but after `f instanceof Function` it's not OK.

See also [this Stack Overflow question & answer](https://stackoverflow.com/a/38470194/643091).

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.