4 ms·
people should really try non-nullable types in typescript and kotlin, in addition to smart-casting. Then they would realize optionals are niche and cumbersome.
by SemanticStrengh 5y ago
people should really try non-nullable types in typescript and kotlin, in addition to smart-casting. Then they would realize optionals are niche and cumbersome.
- chriskrycho 5y agoI’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.