Util

isDefined

Type-narrowing predicate that filters out null and undefined — perfect as the callback for Array.filter when you want a strictly-typed non-nullish list.

Usage

import { isDefined } from 'ngwr/utils';

const items: (string | null | undefined)[] = ['a', null, 'b', undefined];
const present = items.filter(isDefined);   // string[] — narrowed

Why 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[]                          ← clean

API

NameDescriptionTypeDefault
isDefined(v)Type-narrowing guard that excludes null and undefined. Composes cleanly with Array.filter.<T>(v: T | null | undefined) => v is T