We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d5bcae1 commit 648f7c6Copy full SHA for 648f7c6
libs/ngxtension/filter-nil/src/filter-nil.ts
@@ -1,7 +1,12 @@
1
import { filter } from 'rxjs';
2
3
+// TypeScript's built-in `NonNullable` doesn't distribute properly over generic type parameters
4
+// in type predicate contexts, causing the type guard to fail. This custom conditional type
5
+// forces distribution by being evaluated directly in the generic context.
6
+type NotNullable<T> = T extends null | undefined ? never : T;
7
+
8
export const filterNil = <T>() =>
9
filter(
- (value: T): value is NonNullable<T> =>
10
+ (value: T): value is NotNullable<T> =>
11
value !== undefined && value !== null,
12
);
0 commit comments