literal: [Question] Why doesn't `_Any` include `nil`?
In TypeScript, any includes nil. It kinda looks like it should here as well.
Also, if we can’t make _Any include nil could we get a _Any_Nil (can be a different name) type from the library?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20
I think it’s really useful. I guess
_Requiredwould work. If_Anyallowsnil, all the arguments set to_Anywould be optional. People use required arguments all the time even if they don’t use types.Not to get too philosophical, but the fact that
nilis an object kinda makes it a “thing”, no?But it’s short for anyTHING. 🤣
In case you were looking for more feedback:
I’ve also been mildly surprised that
_Anydoesn’t containnil, and have just now realized_Voidexists 😅On intuition, I’d expect
_Anyto includenil, and something like_Existsto include everything exceptnilThat said, it won’t be hard for me to get used to whatever naming you land on.
Also, if you’re pondering this change, this is the stage to make it when it’s so early on.
Yes,
_Voidwould normally be used of inconsequential return values. However it does fulfil this role because it always matches. The _Never type is the opposite, which doesn’t match anything or nothing. I’m okay with renaming_Voidto_Unit.In my mind, “any” is short for any-THING, and that does not include nothing. We do have
_Voidthat will accept anything or nothing. I know any in TypeScript includes null and undefined but in Kotlin, it is the root of all non-nullable types. Kotlin too has Unit (which is another name for Void). I think Void is the type you’re looking for here.Interesting observation. If Any is considered the top type of the type system in literal then, yeah it should include the nil value (NilClass is a subclass of Object and it’s Rubys universal base class)