-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
[feature request] add new isNullish
predicate function
#75
Comments
Good references, and pretty much identical, but the naming bikeshedding might have already taken place in a little Twitter poll i ran a few months ago. Only like a handful of people voted, so it doesn't really mean much, but good arguments about the ES spec “cementing” the word to have that meaning (if that is a bad reason for Do you not like the Suffix
Usage notes
|
One would think that with the word Then you have a beauty like this from the TS 4.8 release post linked above: function throwIfNullable<T>(value: T): NonNullable<T> {
if (value === undefined || value === null) {
throw Error("Nullable value!");
}
// Used to fail because 'T' was not assignable to 'NonNullable<T>'.
// Now narrows to 'T & {}' and succeeds because that's just 'NonNullable<T>'.
return value;
} Where they'd clearly have called this function
|
and
and
… all sound fine to me, but the fact that the most official JS documentation (MDN web docs) use |
Checks whether something is
null
orundefined
.Would be useful for OpenINF/openinf-util-object#133. We can have it out in the next minor…
Can this be achieved solely using Nullish coalescing? Maybe in the TS, but now wondering what ES year we are searching for compatibility with since this is a relatively new language feature.
Refs: https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#improved-intersection-reduction-union-compatibility-and-narrowing
/cc @septs @ignoreintuition
The text was updated successfully, but these errors were encountered: