Skip to content

Latest commit

 

History

History
26 lines (15 loc) · 877 Bytes

js-utils.hasitems.md

File metadata and controls

26 lines (15 loc) · 877 Bytes

Home > @apextoaster/js-utils > hasItems

hasItems() function

Test if a value is an array with some items (length > 0).

This is not a general replacement for .length > 0, since it is also a typeguard: if (hasItems(val)) else { val } will complain that val is never in the else branch, since it was proven not to be an array by this function, even if val is simply empty.

Signature:

export declare function hasItems<T>(val: Maybe<Array<T>>): val is Array<T>;

Parameters

Parameter Type Description
val Maybe<Array<T>>

Returns:

val is Array<T>