sindresorhus / ts-extras

Essential utilities for TypeScript projects
MIT License
587 stars 15 forks source link

Add `isEmpty` function #1

Closed jonahsnider closed 3 years ago

jonahsnider commented 3 years ago

Check whether an array is empty. Helpful type guard to have since TypeScript array type definitions aren't very safe.

declare function isEmpty(array: readonly unknown[]): array is [];

isEmpty([1, 2, 3]);
//=> false

isEmpty([]);
//=> true
sindresorhus commented 3 years ago

Thanks :)