Skip to content

isGeneratorFunction

The isGeneratorFunction function checks if the provided value is a generator function.

Syntax

typescript
isGeneratorFunction(value: any): value is GeneratorFunction;

Parameters

ParameterTypeDescription
valueanyValue to be checked

Returns

TypeDescription
booleanTrue if it is a generator function

Examples

typescript
isGeneratorFunction(function* () {}); // => true
isGeneratorFunction(() => {}); // => false

Notes

  • Useful for validating functions before using for-of or yield.

References

Released under the MIT License.