Hacker News new | ask | show | jobs
by ImprobableTruth 1362 days ago
>I miss being able to spread the properties of one type into another, rather than having to inherit from an interface)

What would that achieve that intersection types don't already?

2 comments

Spreads are ordered, and try to match the semantics of object spreads at runtime. Intersection types don't do that, they express that the type is both things at the same time. It is most obvious when dealing with types that have overlapping properties: [typescript with intersections](https://www.typescriptlang.org/play?#code/C4TwDgpgBAglC8UDeA...) [flow with spreads](https://flow.org/try/#0C4TwDgpgBAglC8UDeAfAUFTUBmB7XAXFAHYCu...).
They map onto same type as runtime spread, ie. order matters last one overwrites.