4 ms·
I’ve used TypeScript’s handling extensively as well as Rust’s, and I would say that there are actually significant tradeoffs, rather than it being an easy win f
by chriskrycho 4y ago
I’ve used TypeScript’s handling extensively as well as Rust’s, and I would say that there are actually significant tradeoffs, rather than it being an easy win for either. In particular, the fact that `| null | undefined` is just another union type can be very nice but also makes it annoying/impossible to implement a lot of the niceties like Rust’s `unwrap_or_default()` in a generic way (though some of that is just a function of how different Rust’s trait system is from JS). It also has weird fallout in the ways that it collapses together `map` and `andThen`/`flatMap`/`bind`. And it’s kind of annoying that it is a special case rather than having all the exact same tooling as all other types in the language the way sum type–based optional types do. On balance I very much prefer the Rust/Swift/etc. approach.