I am trying to use the generator function in typewriting. But the compiler gives an error
error TS2339: Property 'next' does not exist on type
Below is the closest example of my code.
export default class GeneratorClass { constructor() { this.generator(10); this.generator.next(); } *generator(count:number): Iterable<number | undefined> { while(true) yield count++; } }
{while (true) yield count ++; }} rel = noreferrer> Here is a link to the playground for the same
There is a method in the generator nextthat returns the function, not the generator function itself.
next
export default class GeneratorClass { constructor() { const iterator = this.generator(10); iterator.next(); } *generator(count:number): IterableIterator<number> { while(true) yield count++; } }
I saw this error because my tsconfig.json was aimed at es5.
es5
I just changed (pulled) from:
"target": "es5", "lib": [ "es5", "es2015.promise" ]
at
"target": "es6", "lib": [ "es6" ]
and the error has disappeared.
. VS IntelliSense, .
console.log(function.constructor.name)//
console.log(function.constructor.name)
tsconfig.json target: esnext
target: esnext
console.log(function.constructor.name)//GeneratorFunction
@vossad01
Source: https://habr.com/ru/post/1671732/More articles:How to make a triangular border sensitive on the upper side - javascriptLazyInitializationException using patch add with Spring HATEOAS - springAzure SQL DW for Azure SQL DW using Polybase - azureWhy do my scatterplots look exactly the same though I am transforming a predictor? - rHow to asynchronously write and read from the same file in node? - javascriptWhy is this sql correct? (sql injection) - sqlSetting a timeout in Qt Test - c ++Can a prologue respond vaguely, and not just yes or no? - prologC # project does not function F # type `[ ]` - c #How to set port for express server dynamically? - javascriptAll Articles