facebook / facebook/flow

`boolean` is incompatible with `true | false`

Open
#4,196 6 comments 14 reactions 0 assignees View on GitHub
feature request
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Flow does not let you pass a `boolean` where `(true | false)` is accepted.
```js
// @flow

declare function foo(true | false): void
declare function bar(): (boolean)

foo(bar())
```
This [fails](https://flow.org/try/#0PTAEAEDMBsHsHcBQiAmBTAxtAhgJzaJAK4B2GALgJawmgYAWssAzmgBTm5EEA+h20VgEoAXKABusSilSYc+QqQrVa6DNPajQbAEZNoabCSHIGTVmzUa2Qk4jMt2zStGgBPS5mu27xMlRpQZ1cPcTE9WAMjIVAAb0RQUHxyIlxacVAAflBOblAxSAFWRABfRCA) with the following error:
```
6: foo(bar())
^ boolean. This type is incompatible with
3: declare function foo(true | false): void
^ union: boolean literal `true` | boolean literal `false`
```

Why is this? I would expect `boolean` to be defined internally as just `true | false`, but that seems not to be the case.

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.