【发布时间】:2018-05-15 02:06:34
【问题描述】:
我想使用 ES6 扩展运算符将 NodeList 转换为 Array。我的项目使用 TypeScript,但它抛出了一个错误。
const slides = [...document.querySelectorAll('.review-item')];
这是抛出的错误,error TS2461: Type 'NodeListOf' is not an array type
该代码在 Babel 中是可能的。是否可以在 TypeScript 中使用,或者我是否需要使用其他方法,例如 Object.keys()?
【问题讨论】: