Rename Nullable to Nullish
I find the Nullable module name very confusing because usually, it's 'a | null, not 'a | undefined | null It's not super critical to me, but I think for ReScript's future, it will be better to rename it to Nullish early on (at least do it in rescript-core).
According to https://tc39.es/ecma262/ nullish is precisely the values that can be both null and undefined.
Because right now for users coming from JS/TS there's the following situation:
| TS type | Expectation | Reality |
|---|---|---|
| T | undefined | optional<'a> | option<'a> |
| T | null | nullable<'a> | null<'a> |
| T | undefined | null | nullish<'a> | Js.Nullable.t<'a> |
I think that we shouldn't do anything with option and null; that's the language specific. But the problem is that usually nullable means T | null instead of T | undefined | null.
What do you think?
The word "nullish" has never been adopted by the ecosystem. I think that would be a little strange.
The words I see the most are "maybe" or "optional".
The word "nullish" has never been adopted by the ecosystem. I think that would be a little strange.
With the nullish coalescing operator I'd expect it to be pretty understandable.
I don't think this is a big issue since option is used much more frequently. However, I have always found Nullable to be a strange name.
I think it is reasonable that some of these modules could be removed and made more consistent:
let _: Js.null<'a> = Js.null
let _: Js.Null.t<'a> = Js.Null.empty
let _: Js.undefined<'a> = Js.undefined
let _: Js.Undefined.t<'a> = Js.Undefined.empty
let _: option<'a> = None
let _: Js.null_undefined<'a> = Js.Null_undefined.null
let _: Js.null_undefined<'a> = Js.Null_undefined.undefined
let _: Js.Nullable.t<'a> = Js.Nullable.null
let _: Js.Nullable.t<'a> = Js.Nullable.undefined
And being able to easily pattern match would be big.
It is called as nullable for even TypeScript people: https://www.typescriptlang.org/docs/handbook/utility-types.html#nonnullabletype
Maybe we can remove something inconsistent, but I don't think the "nullable" is not a problem