{"id":"56fbd5d6e71001d7","repo":"sindresorhus/is","slug":"expected-value-which-is-generator-received-valu","errorCode":null,"errorMessage":"Expected value which is `Generator`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Generator`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1647,"sourceCode":"\t}\n}\n\nexport function assertFormData(value: unknown, message?: string): asserts value is FormData {\n\tif (!isFormData(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('FormData', value));\n\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));","sourceCodeStart":1629,"sourceCodeEnd":1665,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1629-L1665","documentation":"Thrown by `assertGenerator()` when `isGenerator()` fails — the value is not a generator *object* (the iterator returned by invoking a generator function, tagged `Generator`). Note the distinction: the generator function itself does not pass this check.","triggerScenarios":"`is.assert.generator(value)` called with a generator function that was never invoked, a plain iterator/iterable (arrays, custom `[Symbol.iterator]` objects), or an async generator object.","commonSituations":"Passing `myGenFn` instead of `myGenFn()`; assuming any iterable qualifies — plain iterators lack the `Generator` tag and `throw`/`return` semantics; mixing up sync and async generators (async ones need `isAsyncGenerator`).","solutions":["Invoke the generator function first and assert the returned object: `assertGenerator(gen())`.","If the value is an async generator, use `is.asyncGenerator` / `assertAsyncGenerator` instead.","If any iterable is acceptable, assert with `is.iterable` rather than `is.generator`."],"exampleFix":"// before\nassertGenerator(numbersGen); // the function itself\n// after\nassertGenerator(numbersGen()); // the generator object","handlingStrategy":"type-guard","validationCode":"const isGen = value != null && typeof value.next === 'function' && typeof value.throw === 'function' && typeof value[Symbol.iterator] === 'function';\nif (!isGen) throw new TypeError('Expected Generator object');","typeGuard":"function isGenerator(value: unknown): value is Generator {\n  const v = value as Generator | null;\n  return v != null && typeof v.next === 'function' && typeof v.throw === 'function' && typeof v.return === 'function';\n}","tryCatchPattern":"try {\n  assert.generator(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* likely passed the generator function, not its result */ }\n  else throw error;\n}","preventionTips":["Call the generator function first — pass `gen()` (a Generator object), not `gen` (a GeneratorFunction)","A plain iterator or array is not a Generator; it must have next/return/throw with the generator prototype","Don't confuse sync Generator with AsyncGenerator — `async function*` produces a different type"],"tags":["generator","iterator","type-assertion","runtime-validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}