Re:TypeScript 3.7
by paulddraper on Wednesday November 06, 2019 @10:42AM
(#21463597)
Or, use Maybe/Option and have as many levels of nonexistence as you want.
Option[Option[Option[T]]]
Not that it would necessarily be very useful, but choosing 2 values of nonexistence is very arbitrary.Usually zero or one level of nonexistence is enough.
Re:TypeScript 3.7
by eyelidlessness on Thursday November 07, 2019 @11:45AM
(#21474788)
There is yet a third type of missing value in JS: empty array slot. This appears when you create an array with a length but no values for indexes in that length, e.g. `new Array(100)`.
Edit: also `undefined` is a value in JS as well.
It can be useful to have the latter case distinguished in a dynamic language because it can enable certain powerful patterns. At the end of the day, compressing both these cases to a single concept of null would be lossy. This may have certain advantageous implications for simplicity, but you're trading that off for language power. Which you favour more of course depends on the usecase.