Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rauschma opened this issue Jan 12, 2025 · 3 comments
Open

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

rauschma opened this issue Jan 12, 2025 · 3 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@rauschma
Copy link

πŸ”Ž 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

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jan 13, 2025
@RyanCavanaugh
Copy link
Member

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

@tbroyer
Copy link

tbroyer commented Jan 13, 2025

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

@rauschma
Copy link
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”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

4 participants