isNonNull

Type guard para filtrar valores null y undefined.

#data #type-guard #utility
export const isNonNull = <T>(
value: T,
): value is NonNullable<T> => value != null;
// Usage
const items = [1, null, 2, undefined, 3];
const filtered = items.filter(isNonNull);
// type: number[]
// value: [1, 2, 3]

Comparte este snippet

Comentarios