-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
Conversation
static ofUndefinable<Value>(value: Value | undefined): Optional<Value> { | ||
if (value === undefined) { | ||
return Optional.empty(); | ||
static ofUndefinable<Value>(value: Value | undefined | null): Optional<Value> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
5418648
to
20ff2dc
Compare
20ff2dc
to
5c33df3
Compare
I had |
6fd7581
to
8e01c70
Compare
Thanks @NolwennD |
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. |
Fix #10897