Dhe*_*wal 3 javascript typescript angular
我正在使用每个函数来检查是否选中了网格中的特定复选框,我正在使用angular 2,下面是我的代码:
// Typescript code
this.toggle = this.contactlist.every(item => item.checked);
// JS output is
this.toggle = this.contactlist.every(function(item) {
return item.checked;
});
Run Code Online (Sandbox Code Playgroud)
现在,我想在每个函数中包含更多代码,因此我尝试了以下操作:
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'.
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
更改为
this.toggle = this.contactlist.every(item => {
console.log('Item:', item)
return item.checked;
});
Run Code Online (Sandbox Code Playgroud)
添加return部分
| 归档时间: |
|
| 查看次数: |
2308 次 |
| 最近记录: |