如何解决为什么 Typescript 在 foreach 中使用带有匿名函数的“each”时不显示错误,但在使用箭头函数时抛出正确的错误?
在打字稿中,我有以下代码抛出错误,我知道“每个”无效,我必须使用“forEach”
objTablesToCheck.forEach(objTable => {
for (let i = aggregateStartIdx; i < numOfCells; i++) {
//TypeScript thorws error at compile time and I know "each" is not valid and I have to use forEach
//getNthColumnCells return type is Array<HTMLTableCellElement>
this.getNthColumnCells(objTable,colNum).each(objCell => {
//my Logic
}
}
}
然而,TypeScript 在编译时不会抛出错误?为什么“每个”对这个代码块有效?
objTablesToCheck.forEach(objTable => {
for (let i = aggregateStartIdx; i < numOfCells; i++) {
//TypeScript does NOT throw error at compile time
//getNthColumnCells return type is Array<HTMLTableCellElement>
this.getNthColumnCells(objTable,colNum).each(function(objCell) {
//my Logic
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。