ecmascript 6 - TypeScript and custom iterators -


i want create iterator array in typescript, how must fix code not transpilation error? generics or so?

let array4 = [10, 20, 30];  array4[symbol.iterator] = function () {   let = 0;   return {     next: function () {       i++;       return {         value: < 4 ? array4[i - 1] : undefined,         done: >= 4 ? true : false       };     }   }; };  let it4 = array4[symbol.iterator]();  console.log(it4.next()); console.log(it4.next()); console.log(it4.next()); console.log(it4.next()); 

like so:

array4[symbol.iterator] = function* () {     let = 0;     while (i < 3) {         i++;         yield array4[i - 1];     } }; 

you without generator function if like, need find correct signature of iterableiterator<t>. let me know if need that.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -