basarat / typescript-book

:books: The definitive guide to TypeScript and possibly the best TypeScript book :book:. Free and Open Source 🌹
https://basarat.gitbook.io/typescript/
Other
20.81k stars 2.55k forks source link

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

Open pjustino opened 7 years ago

pjustino commented 7 years ago

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 requires the value to be defined : interface IteratorResult { 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

basarat commented 7 years ago

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:

gauravshah786 commented 7 years ago

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