sindresorhus/is · error · TypeError

Expected value which is `AsyncIterable`, received value of t

Error message

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

What it means

Thrown by `assertAsyncIterable(value)` when the value does not have a callable `[Symbol.asyncIterator]` method. This is the check backing `for await...of` compatibility: sync iterables (arrays, Sets, sync generators) fail it because they implement `Symbol.iterator`, not `Symbol.asyncIterator`.

Source

Thrown at source/index.ts:1480

		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)) {
		throw new TypeError(message ?? typeErrorMessage('AsyncGeneratorFunction', value));
	}
}

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

export function assertBigint(value: unknown, message?: string): asserts value is bigint {
	if (!isBigint(value)) {
		throw new TypeError(message ?? typeErrorMessage('bigint', value));
	}
}

export function assertBigInt64Array(value: unknown, message?: string): asserts value is BigInt64Array {
	if (!isBigInt64Array(value)) {
		throw new TypeError(message ?? typeErrorMessage('BigInt64Array', value));
	}
}

export function assertBigUint64Array(value: unknown, message?: string): asserts value is BigUint64Array {
	if (!isBigUint64Array(value)) {
		throw new TypeError(message ?? typeErrorMessage('BigUint64Array', value));

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. Await the value first if it's a Promise of an iterable, or call the async generator function to get its iterator.
  2. Wrap sync iterables when the consumer demands async: `(async function * () { yield * syncIterable; })()`.
  3. If sync sources are legitimate, loosen the contract to `assert.iterable` or accept both and branch on `Symbol.asyncIterator in value`.
  4. On older runtimes, upgrade Node/target so `Symbol.asyncIterator` and async-iterable ReadableStream exist.

Example fix

// before
processStream([1, 2, 3]); // sync array, assert.asyncIterable throws
// after
processStream((async function * () { yield * [1, 2, 3]; })());
Defensive patterns

Strategy: type-guard

Validate before calling

if (value == null || typeof value[Symbol.asyncIterator] !== 'function') {
  // wrap or reject before assert.asyncIterable(value)
}

Type guard

function isAsyncIterable(value) {
  return value != null && typeof value[Symbol.asyncIterator] === 'function';
}

Try / catch

try {
  assert.asyncIterable(value);
} catch (error) {
  if (error instanceof TypeError) { /* sync iterable or plain object given */ }
  else { throw error; }
}

Prevention

When it happens

Trigger: Passing an array or other sync iterable where an async iterable is required; passing a Promise of an iterable (`Promise<Item[]>`) without awaiting; passing an uncalled `async function*`; environments/polyfills where `Symbol.asyncIterator` is missing so nothing gets tagged.

Common situations: Mixing sync and async data sources in a pipeline that requires `for await` inputs; forgetting to `await` a fetch that resolves to a stream; older Node (<10) or ES targets without `Symbol.asyncIterator`; passing a Web ReadableStream in runtimes where it isn't yet async-iterable (older Node/browsers).

Related errors


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