Búsqueda de sitios web

javascript - función .every en typescript + angular 2


Estoy utilizando todas las funciones para verificar si una casilla de verificación en la cuadrícula está marcada o no, estoy usando Angular 2 y a continuación está mi código para hacer eso:

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

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

Ahora quiero incluir más código dentro de esa función, así que intenté esto:

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

¿Cómo puedo resolverlo?

Respuesta #1

cámbialo a

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

agregar la parte return

Artículos relacionados