Skip to content

isNonEmptyList

isNonEmptyList<A>(list): list is NonEmptyList<A>

Defined in: Types/NonEmptyList.ts:29

Type guard that checks if an array is non-empty.

A

readonly A[]

list is NonEmptyList<A>

const items: string[] = getItems();

if (isNonEmptyList(items)) {
  // TypeScript knows items has at least one element
  const first = items[0]; // string, not string | undefined
}