我正在使用每个函数来检查网格中的特定复选框是否被选中,我使用的是角度2以下是我的代码来执行此操作:
// Typescript code
this.toggle = this.contactlist.every(item => item.checked);
// JS output is
this.toggle = this.contactlist.every(function(item) {
return item.checked;
});
现在我想在每个函数中包含更多代码,所以我尝试了这个:
this.toggle = this.contactlist.every(item => {
item.checked;
console.log('Item:', item)
});
// In Webpack it gives me this error
Argument of type '(item: any) => void' is not assignable to parameter of type '(value: any, index: number, array: any[]) => boolean'.
Type 'void' is not assignable to type 'boolean'.
我如何解决?
答案 0 :(得分:4)
将其更改为
this.toggle = this.contactlist.every(item => {
console.log('Item:', item)
return item.checked;
});
添加return
部分