facebook / facebook/flow

Type hole with compatibility between optional parameters/extra parameters

Open
#3,049 4 comments 2 reactions 0 assignees View on GitHub
bug Typing: soundness
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

```js
//@flow

const x = (a: number = 1): number => a;
const y: () => number = x;
// No Flow error
// Runtime error: Uncaught TypeError: y(...).toFixed is not a function
y('x').toFixed();

const z: (a: string) => number = y;
// No Flow error
// Runtime error: Uncaught TypeError: z(...).toFixed is not a function
z('x').toFixed();
```

I expected Flow to either report that `(number|void) => number` is incompatible with `() => number`, or that `() => number` is incompatible with `(string) => number`. Either would fix this problem, but allowing both in combination is definitely unsound.

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.