sindresorhus/is · error · TypeError

Expected value which is `Iterable`, received value of type `

Error message

Expected value which is `Iterable`, received value of type `${is(value)}`.

What it means

Thrown by `assertIterable()` (source/index.ts:1699) when the value has no callable `[Symbol.iterator]` method (`isIterable` checks `isFunction(value?.[Symbol.iterator])`). It protects code that is about to use `for...of`, spread, or `Array.from` on the value.

Source

Thrown at source/index.ts:1701

		throw new TypeError(message ?? typeErrorMessage('Int32Array', value));
	}
}

export function assertInt8Array(value: unknown, message?: string): asserts value is Int8Array {
	if (!isInt8Array(value)) {
		throw new TypeError(message ?? typeErrorMessage('Int8Array', value));
	}
}

export function assertInteger(value: unknown, message?: string): asserts value is number {
	if (!isInteger(value)) {
		throw new TypeError(message ?? typeErrorMessage('integer', value));
	}
}

export function assertIterable<T = unknown>(value: unknown, message?: string): asserts value is Iterable<T> {
	if (!isIterable(value)) {
		throw new TypeError(message ?? typeErrorMessage('Iterable', value));
	}
}

export function assertMap<Key = unknown, Value = unknown>(value: unknown, message?: string): asserts value is Map<Key, Value> {
	if (!isMap(value)) {
		throw new TypeError(message ?? typeErrorMessage('Map', value));
	}
}

export function assertNan(value: unknown, message?: string): asserts value is number {
	if (!isNan(value)) {
		throw new TypeError(message ?? typeErrorMessage('NaN', value));
	}
}

export function assertNativePromise<T = unknown>(value: unknown, message?: string): asserts value is Promise<T> {
	if (!isNativePromise(value)) {
		throw new TypeError(message ?? typeErrorMessage('native Promise', value));

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. If it's a plain object, iterate its entries explicitly: `Object.entries(obj)` (arrays of entries are iterable).
  2. If it's an async iterable, use `assertAsyncIterable()` and `for await...of` instead.
  3. Wrap single values in an array (`[value]`) when the producer may return either one item or many.
  4. Convert array-likes with `Array.from(arrayLike)` before asserting.

Example fix

// before
const config = {a: 1, b: 2};
assertIterable(config); // throws — plain object
// after
const entries = Object.entries(config);
assertIterable(entries);
Defensive patterns

Strategy: type-guard

Validate before calling

if (value == null || typeof value[Symbol.iterator] !== 'function') {
  value = [value]; // or reject
}

Type guard

const isIterable = (v: unknown): v is Iterable<unknown> => v != null && typeof (v as any)[Symbol.iterator] === 'function';

Prevention

When it happens

Trigger: Passing a plain object `{a: 1}` (objects are not iterable), null/undefined, a number, or an async-only iterable (has `Symbol.asyncIterator` but not `Symbol.iterator`) to `assertIterable()`.

Common situations: Treating a JSON object as if it were an array of entries; passing an async generator where a sync iterable is expected; APIs that return a single item instead of a collection depending on input; forgetting that array-like objects (e.g. `{length: 2, 0: 'a', 1: 'b'}`) are not iterable.

Related errors


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