Shape of a union should be equal to a union of shapes
http://tryflow.org/#0059ecd017fd594acb7a5a23e0b15f06
/* @flow */
type Square = { shape: "square"; size: number; };
type Circle = { shape: "circle"; radius: number; };
type Form = Square | Circle;
type FormUpdate1 = $Shape<Square> | $Shape<Circle>;
type FormUpdate2 = $Shape<Form>; // should be same as FormUpdate1
var f: FormUpdate1 = { size: 100 }; // ok
var g: FormUpdate2 = { size: 100 }; // errors :(
Unions are convenient to describe a state of a react component. And the only function which is allowed to modify the state has the signature setState(stateUpdate: $Shape<State>): void. When State is a union type this definition breaks, as demonstrated by the example above.
I agree with your reasoning here—this should work. I wonder if other parameterized types exhibit similar issues with union/intersection.
shouldn't f and g need to be { shape: "square", size: 100 }? your point stands though
@mroch the shape key shouldn't be necessary because T : $Shape<O> for any T having a subset of the keys in O, for example var o: $Shape<{ foo: string }> = {} is a valid statement.
@pasha-mf I did some digging around the actual intended meaning of $Shape and it's a it more nuanced than "shape-of-T is an object with a subset of keys from T and subtype-compatible values."
This doesn't affect your issue, but you might want to look over what I wrote in #746, or possibly even wrap your head around the implementation itself to ensure the provided semantics match your expectations.
@samwgoldman What's your sense of this issue right now, given what you know about $Shape?
With Partial it works. $Shape is dead