Re:Optional If Expressions
by Nullabillity on Saturday April 15, 2023 @09:11AM
(#35580323)
It's not quite the same though. Since TypeScript uses union types, `T | undefined | undefined` is equivalent to `T | undefined` (and might even be `T`, depending on how that is defined!), while `Option<Option<T>>` is always a distinct type from `Option<T>`
[ Parent
| on HN ]
Which is why TypeScript has T | null | undefined <taps temple>
Re:Optional If Expressions
by Waterluvian on Saturday April 15, 2023 @11:52AM
(#35581748)
There’s no one right answer but this is how I pick, in many cases, when to use null vs undefined.
Re:Optional If Expressions
by eyelidlessness on Saturday April 15, 2023 @12:57PM
(#35582347)
Agree (at least for non-personal projects, where I might be more inclined to use Option/Result types). Wherever possible, I use null as an explicit value when a reference is present but not currently assigned a value, and treat undefined as absence of a reference. I try not to even use the undefined keyword if possible (which is sometimes necessary in types, but I can’t remember the last time I used it in runtime code).
Re:Optional If Expressions
by Nullabillity on Saturday April 15, 2023 @09:12PM
(#35586327)
That still doesn't let you represent `Option<Option<Option<T>>>`, requires you to remember the difference between null and undefined, and fails silently if you screw any of it up.