{"id":"fe6498b5c2b73b56","repo":"sindresorhus/is","slug":"expected-value-which-is-asyncgenerator-received","errorCode":null,"errorMessage":"Expected value which is `AsyncGenerator`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `AsyncGenerator`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1468,"sourceCode":"\t}\n}\n\nexport function assertArrayLike<T = unknown>(value: unknown, message?: string): asserts value is ArrayLike<T> {\n\tif (!isArrayLike(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('array-like', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport function assertAsyncFunction(value: unknown, message?: string): asserts value is Function {\n\tif (!isAsyncFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('AsyncFunction', value));\n\t}\n}\n\nexport function assertAsyncGenerator(value: unknown, message?: string): asserts value is AsyncGenerator {\n\tif (!isAsyncGenerator(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('AsyncGenerator', value));\n\t}\n}\n\nexport function assertAsyncGeneratorFunction(value: unknown, message?: string): asserts value is AsyncGeneratorFunction {\n\tif (!isAsyncGeneratorFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('AsyncGeneratorFunction', value));\n\t}\n}\n\nexport function assertAsyncIterable<T = unknown>(value: unknown, message?: string): asserts value is AsyncIterable<T> {\n\tif (!isAsyncIterable(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('AsyncIterable', value));\n\t}\n}\n\nexport function assertBigint(value: unknown, message?: string): asserts value is bigint {\n\tif (!isBigint(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('bigint', value));","sourceCodeStart":1450,"sourceCodeEnd":1486,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1450-L1486","documentation":"Thrown by `assertAsyncGenerator(value)` when the value is not an async generator object — the object produced by calling an `async function*`. The check requires an async-iterable whose object tag is `AsyncGenerator`; hand-rolled objects implementing `Symbol.asyncIterator`, plain async functions, or the generator function itself (uncalled) all fail.","triggerScenarios":"Passing the async generator function without invoking it (`gen` instead of `gen()`); passing a sync generator object; passing a custom async iterable (e.g. a Node Readable stream or an object with `[Symbol.asyncIterator]`) that is async-iterable but not a true AsyncGenerator; transpiled code where the AsyncGenerator tag is lost.","commonSituations":"Forgetting the call parentheses when handing a generator to a consumer; treating Node streams or paginated API iterators as generators; downlevel transpilation (pre-ES2018 targets) replacing native async generators with polyfilled objects lacking the tag.","solutions":["Call the generator function first: pass `gen()` (the generator object), not `gen`.","If any async-iterable should be accepted, use `assert.asyncIterable` instead — it covers streams and custom iterables.","Ensure the source is declared `async function*`, not a plain function returning an object.","Compile to ES2018+ so native async generators keep their tag."],"exampleFix":"// before\nasync function * pages() { /* ... */ }\nconsume(pages); // function, not generator object — throws\n// after\nconsume(pages());","handlingStrategy":"type-guard","validationCode":"const isAsyncGen = v => v != null && typeof v.next === 'function' && typeof v[Symbol.asyncIterator] === 'function';\nif (!isAsyncGen(value)) { /* handle */ }","typeGuard":"function isAsyncGenerator(value) {\n  return value != null && typeof value.next === 'function' &&\n    typeof value[Symbol.asyncIterator] === 'function';\n}","tryCatchPattern":"try {\n  assert.asyncGenerator(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* passed the generator function instead of calling it? */ }\n  else { throw error; }\n}","preventionTips":["Call the async generator function first — gen() returns the AsyncGenerator, gen itself does not pass","A sync generator is not an AsyncGenerator; check for Symbol.asyncIterator specifically","Async iterables that aren't generators (streams) fail this check — use is.asyncIterable if that's sufficient"],"tags":["type-assertion","async-generator","iteration"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}