3 ms·
Interesting, but I don't really get the difference about intersection types. (abstraction through capabilities) What differentiate an intersection type from a m
by The_rationalist 7y ago
Interesting, but I don't really get the difference about intersection types.
(abstraction through capabilities)
What differentiate an intersection type from a mixin?
Secondly I get it that intersection types in typescript are more permissive but they are mostly functionaly the same, aren't they?
- kaoD 7y agoTraits are similar to mixins, this SE answer explains it better than I could: https://stackoverflow.com/questions/925609/mixins-vs-traits https://stackoverflow.com/questions/925609/mixins-vs-traits Sorry about the intersection confusion, I mixed up things. Intersection generic types are types that adhere to a set of traits (all of them, completely). Since traits don't overlap (even if their method names are the same) their intersection requires them to be defined explicitly. E.g. if you have an interface A { length: number } and an interface B { length: number, size: number } in Rust/Haskell you need to implement both explicitly for your type, while in TS your type just has to adhere to B's shape to be both. TL;DR: it's mostly about the "structural vs nominal" + "traits vs interfaces". But yeah they're functionally the same indeed, sorry for the confusion.