Skip to content

isEmpty

Checks if a value is empty.

Supported types:

  • null / undefined → empty
  • string → length === 0
  • array → length === 0
  • Map / Set → size === 0
  • plain object → no own enumerable properties

Available since v2.0.0

import { isEmpty } from '@helpers4/type';
isEmpty(value: unknown): value is "" | never[] | ReadonlyMap<never, never> | ReadonlySet<never> | null | undefined
ParameterTypeDescription
valueunknownThe value to check

value is "" | never[] | ReadonlyMap<never, never> | ReadonlySet<never> | null | undefined — true if the value is considered empty, false otherwise. Acts as a type guard: the else branch narrows away null, undefined, empty strings, empty arrays, and empty Map/Set. Plain empty objects ({}) are not representable as a distinct type in TypeScript and are therefore not part of the predicate.

Returns true for null, undefined, empty strings, arrays, objects, Maps, and Sets.

isEmpty('')     // => true
isEmpty([])     // => true
isEmpty({})     // => true
isEmpty(null)   // => true

Returns false for values with content.

isEmpty('hello') // => false
isEmpty([1])     // => false
isEmpty(42)      // => false

View source on GitHub