4

I am using every function to check if a particular checkbox in the grid is checked or not, I am using angular 2 and below is my code to do that:

// Typescript code
this.toggle = this.contactlist.every(item => item.checked);

// JS output is
this.toggle = this.contactlist.every(function(item) {
   return item.checked;
});

Now I want to include more code inside that every function so I tried this:

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'.

How I can solve it?

1 Answer 1

6

change it to

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

add return part

Sign up to request clarification or add additional context in comments.

1 Comment

One could add why lambdas behave this way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.