Union of intersection type errors on valid intersection type
It seems that Flow doesn't always deal correctly with union types where one of the types is an intersection type. E.g. consider the following types:
type t1 = {
p1 : number
};
type t2 = {
p2: number
}
type t3 = {
p3 : number
}
type intersected = t1 & t2;
type union = intersected | t3;
type union2 = t3 | intersected;
The following 2 objects compile fine:
const u1 : union = {
p3 : 3
};
const u2 : union = {
p1 : 1,
p2 : 2
};
But this doesn't:
const u3 : union2 = {
p1 : 1,
p2 : 2
};
It errors with:
40: const u3 : union2 = {
^^^^^^ intersection type. This type is incompatible with
29: type union2 = t3 | intersected;
^^ object type
Note that u3 is exactly the same object as u2, and union2 should be the structurally the same type as union. The only difference is the order in which the types are defined in the union type.
It seems to me that this isn't supposed to fail.
Yeah, this sounds to me like an instance of #582. Linking the issues together so we can close them all out once a fix is in. Thanks!
@bhosmer Shouldn't this be closed now? #582 was fixed in 0.20, and the test case presented here does not error for me.
Yup! :)