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

Merged
merged 1 commit into from
Sep 27, 2024

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
@NolwennD
Copy link
Contributor Author

I had NaN as emptyable value, does it a good idea?

@murdos murdos merged commit 3241db3 into jhipster:main Sep 27, 2024
34 checks passed
@murdos
Copy link
Contributor

murdos commented Sep 27, 2024

Thanks @NolwennD

@Gnuk
Copy link
Collaborator

Gnuk commented Sep 28, 2024

Sorry, I've not seen this PR before, but I think it could be interesting to choose a better name than ofNullable like safeOf() or ofSafe(). Because in java, it's ok, there is not this problem like js with null, undefined or NaN. So that's why I think ofNullable is confusing.

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
4 participants