Simplify iteration of custom data structures in TypeScript with iterators

Share this video with your friends

Send Tweet

Traversing items of custom data structures, like trees or linked lists, require knowledge of how that data structure is built. That can lead to problems, as faulty iteration strategies might not visit all the items, or they might not know when they've finished visiting all of them. In this lesson, we're going to look at how TypeScript supports us in building custom ES6 iterators that can be then used by a simple "for..of" loop to ensure we provide an easy to use and reliable API for other developers to traverse our data structures.

- -
- -
~ 5 years ago

Interesting lesson!

Avi Aryan
Avi Aryan
~ 5 years ago

This is such a solid course, thank you Rares.

Stephen
Stephen
~ 5 years ago

So very well explained. Many thanks.

~ 3 years ago

I got this error Type 'null' is not assignable to type 'ListNode<Action>', but it worked for you, why?

~ 3 years ago

"I got this error Type 'null' is not assignable to type 'ListNode<Action>', but it worked for you, why?"

You have to turn off strictNullChecks in your tsconfig.