facebook / facebook/flow

Intersection type incompatible with equivalent type

Open
#3,363 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

In this example:
```
type A = { type: 'a', a: string }
type B = { type: 'b', b: string }
type C = { type: 'a' } & ( A | B )

const a : A = { type: 'a', a: 'a' }
const c : C = { type: 'a', a: 'a' }

const a1 : A = c // (c) intersection. This type is incompatible with (A) object type
const c1 : C = a // fine
```
I believe `C` and `A` should be equivalent (though I might be missing something), but flow is showing an error when assigning a value of type `C` to a variable of type `A`.

Would it be possible for flow deduce that `A` and `C` are equivalent in this case (if they are)?

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.