{"id":"e4ad2384904d7b34","repo":"sindresorhus/is","slug":"expected-value-which-is-asyncgeneratorfunction","errorCode":null,"errorMessage":"Expected value which is `AsyncGeneratorFunction`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `AsyncGeneratorFunction`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1474,"sourceCode":"\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));\n\t}\n}\n\nexport function assertBigInt64Array(value: unknown, message?: string): asserts value is BigInt64Array {\n\tif (!isBigInt64Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('BigInt64Array', value));","sourceCodeStart":1456,"sourceCodeEnd":1492,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1456-L1492","documentation":"Thrown by `assertAsyncGeneratorFunction(value)` when the value's object tag is not `AsyncGeneratorFunction` — the value was not declared with `async function*`. Both plain async functions and sync generator functions fail, as does an already-invoked generator (the resulting generator object is not the function).","triggerScenarios":"Passing `async function` (no star) or `function*` (no async) where `async function*` is required; passing the invoked generator object instead of the function; passing a wrapper (`.bind()`, decorator, jest mock) that returns async iterables but isn't tagged; transpiled output for targets below ES2018 losing the tag.","commonSituations":"Plugin/handler registries requiring streaming producers where users supply a promise-of-array function instead of an async generator function; TypeScript `target` set below es2018 causing production-only failures; accidentally calling the function at registration time.","solutions":["Declare the value as `async function*` (both `async` and `*` are required).","Pass the function itself, not the result of calling it.","If the consumer only needs to invoke it and iterate, consider accepting any function and asserting `assert.asyncIterable` on the call result instead.","Set the compile target to ES2018+ to preserve native async generator function tags."],"exampleFix":"// before\nregister(async function fetchAll() { return items; }); // AsyncFunction, throws\n// after\nregister(async function * fetchAll() { yield * items; });","handlingStrategy":"type-guard","validationCode":"if (Object.prototype.toString.call(fn) !== '[object AsyncGeneratorFunction]') { /* handle */ }","typeGuard":"const isAsyncGeneratorFunction = (fn) =>\n  typeof fn === 'function' &&\n  Object.prototype.toString.call(fn) === '[object AsyncGeneratorFunction]';","tryCatchPattern":"try {\n  assert.asyncGeneratorFunction(fn);\n} catch (error) {\n  if (error instanceof TypeError) { /* async fn, sync generator fn, or plain fn passed */ }\n  else { throw error; }\n}","preventionTips":["Only functions declared as `async function*` pass — neither `async function` nor `function*` alone","Don't pass the invoked result; this check is for the function, not the generator it produces","Transpilation to older targets erases the AsyncGeneratorFunction tag — verify build output"],"tags":["type-assertion","async-generator","function-signature"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}