。打字稿中的每个函数+角2

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)

我该如何解决?

har*_*shr 5

更改为

this.toggle = this.contactlist.every(item => {
    console.log('Item:', item)
    return item.checked; 
});
Run Code Online (Sandbox Code Playgroud)

添加return部分