3 ms·
My biggest wish would be proper sum types. The current way of manually creating tagged unions is really awkward. But that won't be added because there is no na
by the_duke 4y ago
My biggest wish would be proper sum types. The current way of manually creating tagged unions is really awkward.
But that won't be added because there is no native JavaScript equivalent.
- ajkjk 4y agoI wouldn't rule it out. They seem to be increasingly amenable to ergonomic changes that are less coupled to what JS would do in my impression.
- scotty79 4y agoI think it can be safely ruled out. TypeScript tenet which they consistently uphold is that types can't influence behavior of the running code. So to differentiate behavior depending of which part of sum type you got you need some value in the "real world" like a tag that can enable you to do that. Because all the type information is gone at runtime. Strongest violation of this rule I know of are enums that generate their own JS code, but they are their separate thing. Something like sum types would need to be present everywhere. Honestly I kind of like it this way. I'm trying out Rust right now and I'm very often surprised how what I do in one spot depends on huge context of all the generic types that can create wildly different behavior (mostly huge variety compile type error messages in surprisingly varied and distant spots) depending on what types they infer.