Skip to content

tsconfig.json "lib": "dom" should include "dom.iterable"(?)Β #60959

Description

πŸ”Ž Search Terms

lib, dom, dom.iterable

πŸ•— Version & Regression Information

  • An issue as of TypeScript 5.7.2

⏯ Playground Link

No response

πŸ’» Code

// Does TypeScript have the types for DOM iteration?
for (const x of document.querySelectorAll('div')) {}

πŸ™ Actual behavior

  • No error if "lib" is omitted from tsconfig.json.
  • Error if "lib" is ["es2024", "DOM"]
  • No error if "lib" is ["es2024", "DOM", "DOM.iterable"]

πŸ™‚ Expected behavior

Given how broadly supported DOM.iterable is, it should be part of DOM by now(?)

Interestingly, es2024.full looks like this but can’t be used as a value of "lib":

/// <reference lib="es2024" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.asynciterable" />

Additional information about the issue

No response

Activity

  1. RyanCavanaugh commented on Jan 13, 2025

    @RyanCavanaugh
    Member

    It's not clear what you would do if you were targeting a browser that doesn't have iterable, though?

  2. tbroyer commented on Jan 13, 2025

    @tbroyer

    Fair, I don't think many people do that though. And there are other tools to check compatibility (e.g. ESLint's eslint-plugin-compat); is it really TypeScript's role? (note that I don't have a strong opinion on this)

    Fwiw: https://caniuse.com/mdn-api_nodelist_--iterator

  3. rauschma commented on Jan 14, 2025

    @rauschma
    Author

    It's not clear what you would do if you were targeting a browser that doesn't have iterable, though?

    Interesting consideration! Thoughts:

    • Being able to use "es2024.full" seems useful.
    • Not sure if that’s feasible but removing features would help in this case:
      "lib": ["DOM", "-DOM.Iterable"]
    • The rules for what is and isn’t included in DOM could be mentioned in microsoft/TypeScript-DOM-lib-generator. I thought the following rule applied in this case (but reading it again now, it probably doesn’t): β€œA feature needs to be supported by two or more major browser engines to be included here”
  4. fregante commented on Feb 18, 2025

    @fregante

    It's not clear what you would do if you were targeting a browser that doesn't have iterable, though?

    Why is DOM-iterable singled out? Is there a browser that supports ES2024, DOM but does not define NodeList[Symbol.iterator]? This property has been cross-browser for a while.

  5. jakebailey commented on Feb 18, 2025

    @jakebailey
    Member

    For one thing, until 5.0 (well, 5.5) TS still supported ES3, which didn't have iterators, so if they were included in DOM, ES3 users would be unable to use the DOM types.

    Perhaps I'm missing some detail (I don't have the historical context), but I do wonder if we could get away with always loading DOM.Iterable from DOM.

  6. jakebailey commented on Feb 18, 2025

    @jakebailey
    Member

    (Hm, but I don't think we even had ES3 types, so maybe this was never true.)

  7. jakebailey commented on Feb 18, 2025

    @jakebailey
    Member

    Ah, duh, sorry; replace ES3 with ES5 above (and we still support ES5, so the problem has not passed).

  8. lionel-rowe commented on Jul 8, 2025

    @lionel-rowe
    Contributor

    There must be loads of stuff in lib.dom.d.ts that wasn't available in ES5, e.g. AbortController/AbortSignal, TextEncoder/TextDecoder, URLSearchParams, ReadableStream/WritableStream/TransformStream, etc. Why does Symbol.iterable need to be the exception?

    Having something like domnext as an analogue to esnext would be an alternative solution to this. It's just weird having to include a special extra library to enable common patterns like [...document.querySelectorAll(sel)] when the intention is "assume whatever's in the latest DOM spec is available to my code".

  9. jakebailey commented on Jul 8, 2025

    @jakebailey
    Member

    Related: #54500 under "DOM tweaks"

  10. lionel-rowe commented on Jul 8, 2025

    @lionel-rowe
    Contributor

    "lib": ["dom"] will now automatically include dom.iterable as well

    That's great news! πŸŽ‰

  11. phaux commented on Jul 9, 2025

    @phaux

    Maybe this is a good opportunity to also split WebWorker.d.ts into WebWorker.d.ts and ServiceWorker.d.ts?

    #11781 #14877

  12. jakebailey commented on Jul 9, 2025

    @jakebailey
    Member

    Sure, but those are different issues

  13. jakebailey commented on Sep 26, 2025

    @jakebailey
    Member

    This will be fixed by #62111.

  14. added
    SuggestionAn idea for TypeScript
    FixedA PR has been merged for this issue
    CommittedThe team has roadmapped this issue
    and removed
    Needs InvestigationThis issue needs a team member to investigate its status.
    on Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CommittedThe team has roadmapped this issueFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions