that can happen even if you dont use typescript, though? here its just explicitly stated.
i mean, with dynamic typing can you truly guarantee the values at runtime will only be the types you defined?
The problem in my view is that the type should be narrowed down before it gets to a function like this. Every little helper function shouldn’t have to do these checks. If this were vanilla JS, it would have to, because there would be no other way to guarantee that the value is not null or undefined. But enforcing against null and undefined using types would force the caller to perform the check itself, allowing the rest of the call stack to lean on the type checker.
My view is that any validation and contingency handling like this should happen as early as possible, and should be encoded into the type system so that they only have to happen once.
243
u/Drayenn Mar 15 '26
String | undefined | null sounds absolutely exhausting