facebook / facebook/flow

support negation of interfaces in disjoint unions

Open
#7,193 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

```js
/* @flow */

type Foo = Generator | {type: "FOO", payload: boolean} | {type: "BAR", payload: number}
const x: Foo = {type: "BAR", payload: 3}

function test (x: Foo): boolean {
if (x.next != null && typeof x.next === 'function' && x[Symbol.iterator] === x) {
return false
}
switch (x.type) {
case "FOO":
return x.payload
default:
return false
}
}
```

https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVAXAngBwKZgBiccYAvGAOJ4B2eATgIYZz0A8NArgLYBGDAGjBc+g4T370AfGAA+YAN7Z8ALjAAiQgHkt6oTkZZ4jACZreJGHkY0AvnMXK8a9QCEAggCU9YA0bimaiKStqgAxnA0AM4YYAAeasSkFEq4zhoe3vqGxmZgAMyh6FCcNGEYAJaRYBh4MWAAFAlEJACU5pbWNIqoYGAVUI1xAHR0cbEAhBRcMDBgAGTzNWlwgyNjsWRbYADkJWWVkTsLS3EA2gDKWHxwMMMVtUws9AC65NtxrT19ffR4GJx6N0oIwYFE8L0wKE+lEEA8wgALIbDJxfBSQvphRjgjTaXQqDE-P4AoHxYZ+XKEkx4EGcGAYAk-In-QHA0HgyGhWxAA

Type refinement isn't possible when there is a generator in the disjoint union

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.