-
-
Couldn't load subscription status.
- Fork 0
generator
Nicholas Berlette edited this page Jun 19, 2025
·
1 revision
function isGenerator<T = unknown, TReturn = any, TNext = unknown>(
it: unknown,
): it is Generator<T, TReturn, TNext>;Check if the given value is a generator, which is an iterable iterator that was
created with the function*() { ... } syntax.
This is the type of value returned when a generator function
(function*() { ... }) is called, and not the type of the function itself. To
check for the function itself, use isGeneratorFunction instead.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value is a generator, false otherwise.
Generators
import { isGenerator } from "jsr:@nick/is/generator";
function* gen() {
yield 1;
}
const iter = gen();
console.log(isGenerator(iter)); // true
console.log(isGenerator(gen)); // false