Usage
import { isDefined } from 'ngwr/utils';
const items: (string | null | undefined)[] = ['a', null, 'b', undefined];
const present = items.filter(isDefined); // string[] — narrowedWhy ngwr provides this
TypeScript doesn't narrow through inline arrow predicates, so arr.filter(x => x !== null && x !== undefined) returns (T | null | undefined)[] — still nullable. A named function with a type-predicate signature narrows the array element. It's tiny but actually pays off in code that walks collections of optionals.
// Native — TS doesn't narrow through an inline arrow predicate.
const items: (string | null | undefined)[] = ['a', null, 'b'];
const a = items.filter(x => x !== null && x !== undefined);
// ^? (string | null | undefined)[] ← still nullable!
// ngwr — type predicate signature narrows the result.
const b = items.filter(isDefined);
// ^? string[] ← cleanAPI
| Name | Description | Type | Default |
|---|---|---|---|
isDefined(v) | Type-narrowing guard that excludes null and undefined. Composes cleanly with Array.filter. | <T>(v: T | null | undefined) => v is T | — |