Add filterNonNullish #7393
Closed
david-shortman
started this conversation in
Ideas / Feature request
Replies: 1 comment
-
I don't think we'd add that directly to RxJS, especially when you can have a relatively straightforward utility function that is more generally useful: function isNonNull<T>(value: T): value is NonNullable<T> {
return value != null;
}
declare const source$: Observable<false | 0 | '' | null | undefined>;
const result$ = source$.filter(isNonNull); // Observable<false | 0 | ''>; Protip, if you don't like seeing And if you wanted to have your own custom operator, you could do this... (I've changed the name to export const filterOutNonNullish = filter(isNonNull);
// usage
source$.pipe(
filterOutNonNullish
) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It's common to filter non-nullish values. Today, in Typescript, that would be written as:
Instead, it would be preferable to have an operator like:
Existing alternatives include
Defining a custom function:
Using
Boolean
(but this checks for falsy-ness, which is less strict/ more error prone):Beta Was this translation helpful? Give feedback.
All reactions