{"id":"0f6cad263fc52839","repo":"sindresorhus/is","slug":"expected-value-which-is-generatorfunction-recei","errorCode":null,"errorMessage":"Expected value which is `GeneratorFunction`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `GeneratorFunction`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1653,"sourceCode":"\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport function assertFunction(value: unknown, message?: string): asserts value is Function {\n\tif (!isFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Function', value));\n\t}\n}\n\nexport function assertGenerator(value: unknown, message?: string): asserts value is Generator {\n\tif (!isGenerator(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Generator', value));\n\t}\n}\n\nexport function assertGeneratorFunction(value: unknown, message?: string): asserts value is GeneratorFunction {\n\tif (!isGeneratorFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('GeneratorFunction', value));\n\t}\n}\n\nexport function assertHtmlElement(value: unknown, message?: string): asserts value is HTMLElement {\n\tif (!isHtmlElement(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('HTMLElement', value));\n\t}\n}\n\nexport function assertInfinite(value: unknown, message?: string): asserts value is number {\n\tif (!isInfinite(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('infinite number', value));\n\t}\n}\n\nexport function assertInRange(value: number, range: number | [number, number], message?: string): asserts value is number {\n\tif (!isInRange(value, range)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('in range', value));","sourceCodeStart":1635,"sourceCodeEnd":1671,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1635-L1671","documentation":"Thrown by `assertGeneratorFunction()` when `isGeneratorFunction()` fails — the value's object tag is not `GeneratorFunction`. Only functions declared with `function*` pass; regular functions, async functions, and generator objects do not.","triggerScenarios":"`is.assert.generatorFunction(value)` with a normal function, an arrow function, an async generator function (`async function*`, tagged differently), or an already-invoked generator object.","commonSituations":"Transpilers (older Babel/TypeScript targets like ES5) compile `function*` into regular functions using a regenerator runtime, destroying the `GeneratorFunction` tag; passing `gen()` where the function itself was expected; wrapping the generator function in `.bind()` or a decorator that returns a plain function.","solutions":["Ensure the value is the raw `function*` declaration, not a wrapped, bound, or invoked form.","Set the compile target to ES2017+ so generator syntax is preserved rather than transpiled by regenerator.","For `async function*`, use `is.asyncGeneratorFunction` instead."],"exampleFix":"// before (tsconfig)\n\"target\": \"ES5\"\n// after\n\"target\": \"ES2018\"","handlingStrategy":"type-guard","validationCode":"const GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;\nif (!(value instanceof GeneratorFunction)) {\n  throw new TypeError('Expected GeneratorFunction');\n}","typeGuard":"function isGeneratorFunction(value: unknown): value is GeneratorFunction {\n  return typeof value === 'function' && Object.prototype.toString.call(value) === '[object GeneratorFunction]';\n}","tryCatchPattern":"try {\n  assert.generatorFunction(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* passed a normal function or a generator instance */ }\n  else throw error;\n}","preventionTips":["Pass the `function*` itself, not its invoked result (that's a Generator, error 44's case)","Regular functions and async functions fail this check even if they return iterators — declare with `function*`","Beware transpilers (older Babel/TS targets) that compile `function*` into plain functions using regenerator — the tag check then fails; target ES2015+"],"tags":["generator","transpilation","type-assertion","runtime-validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}