Type 'HTML Collection' must have a '[Symbol.iterator]()' method that returns an iterator in a directive

Viewed 401

I have a map in the directive that shows me the error code TS2488 Type 'HTML Collection' must have a '[Symbol.iterator]()' method that returns an iterator .

My map:

map(
  ([headRow, bodyRows]: [HTMLTableRowElement, HTMLCollectionOf<HTMLTableRowElement>]) => [
    [...headRow.children].map(headerCell => headerCell.textContent), // First issue
    [...bodyRows].map(row => [...row.children]) // Second issue
  ]
),

How do I best deal with this problem? Got any advice for me?

1 Answers

HTMLCollection is not iterable but you can get it to ignore that by using "any" on your HTML Elements.

          ([headRow, bodyRows]: [
            HTMLTableRowElement,
            HTMLCollectionOf<HTMLTableRowElement>
          ]) => [
            [...(<any>headRow.children)].map(
              (headerCell) => headerCell.textContent
            ),
            [...(<any>bodyRows)].map((row) => [...row.children])```
Related