类型“ HTML集合”必须具有“ [Symbol.iterator]()”方法,该方法在指令中返回迭代器

我在伪指令中有一个映射,向我显示错误代码TS2488 Type 'HTML Collection' must have a '[Symbol.iterator]()' method that returns an iterator

我的地图:

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

如何最好地解决这个问题?有什么建议吗?

lkf1983 回答:类型“ HTML集合”必须具有“ [Symbol.iterator]()”方法,该方法在指令中返回迭代器

HTMLCollection不可迭代,但是您可以通过在HTML元素上使用“ any”来忽略它。

          ([headRow,bodyRows]: [
            HTMLTableRowElement,HTMLCollectionOf<HTMLTableRowElement>
          ]) => [
            [...(<any>headRow.children)].map(
              (headerCell) => headerCell.textContent
            ),[...(<any>bodyRows)].map((row) => [...row.children])```
本文链接:https://www.f2er.com/2495881.html

大家都在问