Why are dom and dom.iterable separate?

In tsconfig.json you can define additional libs, that give you typings for HTML or DOM "libraries"(? I don't know the correct terminology).

I don't understand why dom and dom.iterable are separate. Were they defined in different ecma modules/versions? Can I use them safely?


  • I suspect it's because iteration (iterables and iterators) weren't added to JavaScript until ES2015, long after TypeScript was well-established. When ES2015 was released, the JavaScript engines in many browsers didn't support iteration (yet),¹ and of course at the time Internet Explorer was still a...thing...that was never going to get new features. So some projects had to target environments that didn't have iteration, so the libs are separate.

    Even here in 2022, IE survives in corporate and government installations (although thankfully that's finally changing), and some folks have to target their apps and pages to those environments, so they wouldn't want to use dom.iterable.

    ¹ ES2015 was the last version of the specification to include significant features that didn't already have implementations in the field. These days, the process that TC39 follows generally doesn't land features in the spec until there are (ideally) a couple of implementations of the feature shipping in the field. Instead, the proposal stays at Stage 3 until that happens, before being moved to Stage 4 by consensus at a TC39 meeting, being added to the editor's draft, and thus being in the next snapshot specification the following June.