facebook / facebook/flow

Type refinement breaks on simple, exact object types

Open
#4,027 2 comments 0 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

I just discovered exact-typed objects in the docs, but refinement doesn't seem to be working correctly:

```js
type S = {| |};

type L = {|
k: string
|};

declare var x: S | L;

if (x.k === undefined) {
// S|L ↦ S
(x: L); //ng
(x: S);
(x: S | L);
} else {
// S|L ↦ L
(x: L); //Flow mistakenly calls this an error
(x: S); //ng
(x: S | L);
}

if (x.k !== undefined) {
// S|L ↦ L
(x: L); //Flow mistakenly calls this an error
(x: S); //ng
(x: S | L);
} else {
// S|L ↦ S
(x: L); //ng
(x: S);
(x: S | L);
}
```

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.