isGenerator
Checks if a value is a generator object (the result of calling a function*).
Distinct from isGeneratorFunction: this predicate targets the instance produced by calling a generator function, not the function itself.
Available since v2.0.3
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
Section titled “Returns”value is Generator<unknown, unknown, unknown> — true if value is a Generator instance
Examples
Section titled “Examples”Distinguish a generator instance from its function
Section titled “Distinguish a generator instance from its function”isGenerator targets the object returned by calling a function*, not the function itself.
Type-narrow to safely call .next()
Section titled “Type-narrow to safely call .next()”Narrows the type to Generator so you can call .next() and .return().
