I can't seem to get exact types in flow to work with object spread.
type Point = {| x: number, y: number |};
const p1: Point = { x: 10, y: 10 };
const p2: Point = { ...p1, y: 5 };
Generates an error object literal. Inexact type is incompatible with exact type
This does't produce an error, but modifies p1:
const p3: Point = Object.assign(p1, {y: 5});
Using Object.assign with an empty object also produces the same object literal error:
const p4: Point = Object.assign({}, p1, {y: 5});
If I use type Point = {x: number, y: number};
then object spread works, but ideally I'd like to use an exact type.
Yeah, this is a known bug. I'm currently working to improve our analysis for object spread to fix this and other issues. The underlying cause is that object spread expressions result in "unsealed" which are incompatible with exact object types. The improved analysis will create sealed objects when possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With