Skip to content
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

Handle null in TypeScript optional #10907

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

NolwennD
Copy link
Contributor

Fix #10897

static ofUndefinable<Value>(value: Value | undefined): Optional<Value> {
if (value === undefined) {
return Optional.empty();
static ofUndefinable<Value>(value: Value | undefined | null): Optional<Value> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should maybe change the name of the method, or add a new method ofNullable(..).
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thank about ofEmptyable but I am not really convinced.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like keeping this one to avoid breaking change and there is no really good naming for this :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about having a single method named ofNullable?
This would then be similar to the java Api that we're using as an aspiration.

I'm not sure we need to worry about breaking things here:

  • we have control over jhlite's webapp and it's not used externally
  • in the generated Optional.ts (that is not changed in this PR by the way), people having already applied it have no reason to re-apply it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True (and we need to change the generated one :D)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rename to ofNullable. Not in scope, but I added NaN to nullable value.

DamnClin
DamnClin previously approved these changes Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle null in TS Optional
3 participants