sindresorhus/is · error · TypeError

Expected value which is `array-like`, received value of type

Error message

Expected value which is `array-like`, received value of type `${is(value)}`.

What it means

Thrown by `assertArrayLike(value)` when the value fails the library's array-like test: a non-null, non-function object with a valid non-negative safe-integer `length` property. Unlike `assertArray`, this accepts strings, `arguments`, NodeLists, and typed arrays — so failing it means the value has no usable `length` at all.

Source

Thrown at source/index.ts:1455

	}

	if (assertion) {
		for (const element of value) {
			// @ts-expect-error: "Assertions require every name in the call target to be declared with an explicit type annotation."
			assertion(element, message);
		}
	}
}

export function assertArrayBuffer(value: unknown, message?: string): asserts value is ArrayBuffer {
	if (!isArrayBuffer(value)) {
		throw new TypeError(message ?? typeErrorMessage('ArrayBuffer', value));
	}
}

export function assertArrayLike<T = unknown>(value: unknown, message?: string): asserts value is ArrayLike<T> {
	if (!isArrayLike(value)) {
		throw new TypeError(message ?? typeErrorMessage('array-like', value));
	}
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
export function assertAsyncFunction(value: unknown, message?: string): asserts value is Function {
	if (!isAsyncFunction(value)) {
		throw new TypeError(message ?? typeErrorMessage('AsyncFunction', value));
	}
}

export function assertAsyncGenerator(value: unknown, message?: string): asserts value is AsyncGenerator {
	if (!isAsyncGenerator(value)) {
		throw new TypeError(message ?? typeErrorMessage('AsyncGenerator', value));
	}
}

export function assertAsyncGeneratorFunction(value: unknown, message?: string): asserts value is AsyncGeneratorFunction {
	if (!isAsyncGeneratorFunction(value)) {

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. Materialize iterables/Sets first: `Array.from(value)` or `[...value]`.
  2. Fix the upstream source so the value isn't undefined/null (missing field, failed lookup).
  3. If the object is index-keyed, add a correct integer `length` property or convert it to a real array.
  4. If you actually need iteration, assert `assert.iterable` instead of array-like.

Example fix

// before
const ids = new Set([1, 2, 3]);
assert.arrayLike(ids); // Set has .size, not .length — throws
// after
assert.arrayLike(Array.from(ids));
Defensive patterns

Strategy: type-guard

Validate before calling

const isArrayLike = v => v != null && typeof v !== 'function' && Number.isSafeInteger(v.length) && v.length >= 0;
if (!isArrayLike(value)) { /* handle */ }

Type guard

function isArrayLike(value) {
  return value != null && typeof value !== 'function' &&
    Number.isSafeInteger(value.length) && value.length >= 0;
}

Try / catch

try {
  assert.arrayLike(value);
} catch (error) {
  if (error instanceof TypeError) { /* missing or invalid .length */ }
  else { throw error; }
}

Prevention

When it happens

Trigger: `assert.arrayLike(value)` receiving null/undefined, numbers, plain objects without `length`, objects with a negative/fractional/NaN `length`, Sets/Maps (which use `size`, not `length`), generators, or functions (explicitly excluded despite having `length`).

Common situations: Passing a `Set` or `Map` where a list is expected (they have `size`, not `length`); iterables from generators that were never materialized; JSON objects keyed by index but missing `length`; undefined values from optional chaining on missing response fields.

Related errors


AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31). Data as JSON: /data/errors/02f1e863d6f29b8d.json. Report an issue: GitHub ↗.