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

Most upvoted comments

I think it’s really useful. I guess _Required would work. If _Any allows nil, all the arguments set to _Any would 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 nil is 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 _Any doesn’t contain nil, and have just now realized _Void exists 😅

On intuition, I’d expect _Any to include nil, and something like _Exists to include everything except nil

That 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, _Void would 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 _Void to _Unit.

In my mind, “any” is short for any-THING, and that does not include nothing. We do have _Void that 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)