Propagate an object with exact stream types

I can not get the exact types in the stream to work with the distribution of objects.

type Point = {| x: number, y: number |}; const p1: Point = { x: 10, y: 10 }; const p2: Point = { ...p1, y: 5 }; 

Generates an object literal . Inaccurate type incompatible with exact type

This does not cause an error, but modifies p1:

 const p3: Point = Object.assign(p1, {y: 5}); 

Using Object.assign with an empty object also results in the same object literal error:

 const p4: Point = Object.assign({}, p1, {y: 5}); 

If I use type Point = {x: number, y: number}; then the object is distributed, but ideally I would like to use the exact type.

+5
source share
1 answer

Yes, this is a known mistake. I am currently working on improving our analysis for distributing objects to fix this and other problems. The main reason is that the distribution expressions of the object result in "unsealed" that are incompatible with the exact types of objects. Improved analysis will create closed objects, if possible.

+6
source

Source: https://habr.com/ru/post/1265807/


All Articles