Skip to content

Rename Nullable to Nullish #6533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DZakh opened this issue Dec 19, 2023 · 5 comments
Closed

Rename Nullable to Nullish #6533

DZakh opened this issue Dec 19, 2023 · 5 comments
Labels
stale Old issues that went stale

Comments

@DZakh
Copy link
Member

DZakh commented Dec 19, 2023

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.
image

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.

@DZakh
Copy link
Member Author

DZakh commented Dec 19, 2023

What do you think?

@cometkim
Copy link
Member

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".

@CarlOlson
Copy link

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.

@cometkim
Copy link
Member

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

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Old issues that went stale label Dec 16, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Old issues that went stale
Projects
None yet
Development

No branches or pull requests

3 participants