typescript-book icon indicating copy to clipboard operation
typescript-book copied to clipboard

missing property in IteratorResult<T> object on page 50 example

Open pjustino opened this issue 8 years ago • 2 comments

Hi,

Thanks for the great work on this book, I'm loving reading it.

I just noticed that on es6 iterator example in page 50 (pdf version) there is a missing value property on next() method.

ES6 interface definition for IteratorResult<T> requires the value to be defined : interface IteratorResult<T> { done: boolean; value: T; }

so on the next() else case the return should be something like: return { value: null, done: true }

Hope this helps.

Regards

pjustino avatar Apr 20 '17 21:04 pjustino

Can you point to the code sample / document section in here https://github.com/basarat/typescript-book/blob/master/docs/iterators.md that you want changed? Thanks! :rose:

basarat avatar Apr 20 '17 23:04 basarat

I want to add here that in Fibonacci sequence code : Iterator does not have to iterate a finite value. The typical example is a Fibonacci sequence: let fib = new Fib(); fib.next() //{ done: false, value: 0 } fib.next() //{ done: false, value: 1 } fib.next() //{ done: false, value: 1 } fib.next() //{ done: false, value: 2 } fib.next() //{ done: false, value: 3 } fib.next() //{ done: false, value: 5 }

After I compile and run this code, I get below result every time next is called {done: true, value: null} I suppose it is because nothing is passed when Fib() is called. screen shot 2017-09-22 at 12 36 13 pm

gauravshah786 avatar Sep 22 '17 17:09 gauravshah786