facebook / facebook/flow

Intersection of types with optional fields is incorrect

Open
#5,929 2 comments 2 reactions 0 assignees View on GitHub
Typing: unions/intersections
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

The `Foo` type should be compatible with the empty object, since `bar` is optional on both sides of the intersection:
```javascript
type Foo = { bar?: true } & { bar?: false }

let x: Foo = {}
```

However, flow errors:
```
3: let x: Foo = {} ^ Cannot assign object literal to `x` because boolean literal `true` [1] is incompatible with boolean literal `false` [2] in property `bar`.
References:
1: type Foo = { bar?: true } & { bar?: false }
^ [1]
1: type Foo = { bar?: true } & { bar?: false }
^ [2]
```

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.