Skip to content

isNonEmptyRecord

Checks whether a value is a non-empty record.

A non-empty record is a plain object that has at least one own enumerable string-keyed property. This helper is designed to validate record-like data structures, not arbitrary objects.

It never throws an error and never mutates input. Use it when you need to ensure that an object represents meaningful key-value data before validation or normalization.

Signature

function isNonEmptyRecord(
  value: unknown
): value is Record<string, unknown>

Parameters

Name Data type Description
value unknown The value to check. Must be a function (per JavaScript's typeof semantics), including class constructors, async functions, generator functions, and bound functions.

Returns

Boolean:

  • true: If the value is a non-empty record.
  • false: Otherwise.

Behavior

Accepts

Accepts plain objects with at least one own enumerable string key:

{ a: 1 }
{ key: "value" }

Objects with a null prototype and properties:

const obj = Object.create(null);
obj.a = 1;

Rejects

  • Empty objects: {}.
  • Arrays: [].
  • Functions: () => {}

Class instances:

new MyClass()
Boxed primitives (Number, String, Boolean)
new Number(1)
new String("hi")
new Boolean(true)
  • Objects with only the symbol keys.
  • Non-objects of any kind (null, primitives).

Note: Plain objects created with Object({...}) are accepted, because they are semantically identical to literal objects.

Implementation Notes

  • Uses Object.keys to detect the presence of own enumerable string keys.
  • Symbol-only objects are rejected by design, as records are defined in terms of string-keyed data.
  • Prototype inspection is used to exclude class instances.
  • Objects created with Object.create(null) are explicitly supported.
  • Boxed primitives are rejected because they are not true plain objects.

Examples

isNonEmptyRecord({ a: 1 }) // true

isNonEmptyRecord({}) // false
isNonEmptyRecord({ [Symbol("s")]: 1 }) // false
isNonEmptyRecord([]) // false

const obj = Object.create(null);
obj.a = 1;
isNonEmptyRecord(obj) // true

isNonEmptyRecord(new Number(1)) // false

Notes

  • This is a semantic type guard.
  • If you only need to check that a value is a record (including empty ones), use a separate helper such as isRecord.
  • This helper does not coerce values and does not inspect inherited properties.
  • The helper is pure, side-effect free, and never throws.