Skip to content

NodeListOf, TS2488 -- for of method that returns an iterator #54351

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

Closed
asottile opened this issue May 22, 2023 · 3 comments
Closed

NodeListOf, TS2488 -- for of method that returns an iterator #54351

asottile opened this issue May 22, 2023 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@asottile
Copy link

Bug Report

🔎 Search Terms

NodeListOf TS2488

I found #2695 which claims that this is fixed but it looks like it wasn't fixed for NodeListOf

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about some things (I read the titles but none of them seemed relevant)
  • I was unable to test this on prior versions because I am lazy

⏯ Playground Link

unfortunately I can't reproduce this in the playground because it does not have a setting for dom.

💻 Code

here's a reproduction instead inline:

tsconfig.json

{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "lib": ["dom", "es2020"],
    "downlevelIteration": true
  },
  "exclude": ["node_modules"],
  "include": ["t.ts"]
}

t.ts

function f(els: NodeListOf<HTMLDialogElement>) {
    for (const el of els) {
        console.log(el);
    }
}

f(document.querySelectorAll('dialog'));

package.json

{
  "dependencies": {
    "typescript": "^5.0.4"
  }
}

🙁 Actual behavior

$ ./node_modules/.bin/tsc
t.ts:2:22 - error TS2488: Type 'NodeListOf<HTMLDialogElement>' must have a '[Symbol.iterator]()' method that returns an iterator.

2     for (const el of els) {
                       ~~~


Found 1 error in t.ts:2

🙂 Expected behavior

(no errors)

@MartinJohns
Copy link
Contributor

You're missing the lib dom.iterable.

@asottile
Copy link
Author

ah then perhaps the diagnostic should be improved, or it should get pulled in by default with dom?

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label May 23, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow or the TypeScript Discord community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants