API reference / @evolu/common / Array / isNonEmptyArray
Function: isNonEmptyArray()
function isNonEmptyArray<T>(array): array is [T, ...T[]];
Defined in: packages/common/src/Array.ts:117
Checks if an array is non-empty and narrows its type to NonEmptyArray.
Use if (!isNonEmptyArray(arr)) for empty checks.
Example
const arr: Array<number> = [1, 2, 3];
if (isNonEmptyArray(arr)) {
firstInArray(arr); // arr is NonEmptyArray<number>
}
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
array | T[] |
Returns
array is [T, ...T[]]