4 ms·
Traits are similar to mixins, this SE answer explains it better than I could: https://stackoverflow.com/questions/925609/mixins-vs-traits https://stackoverflow
by kaoD 7y ago
Traits 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.