Cannot use .some() with array of objects


I'm trying to check wether my array of objects contains an atribute with a specified value. For this I thought of using array.some(), instead of a foreach loop. However I keep getting an error:

error TS2345: Argument of type '(element: ListaDetalhePendenciaAprovacao) => void' is not assignable to parameter of type '(value: ListaDetalhePendenciaAprovacao, index: number, array: ListaDetalhePendenciaAprovacao[]) => boolean'. Type 'void' is not assignable to type 'boolean'.

The code is as follows:

let existeApr = this.pendenciasList.some(element =>{
      !isUndefined(element.isSelected) && element.isSelected

   let existeRej = this.pendenciasList.some(element =>{
      !isUndefined(element.isSelected) && element.isSelected

    existeApr ? this.permiteJustificarAprov=true : this.permiteJustificarAprov=false;
    existeRej ? this.permiteJustificarRej=true : this.permiteJustificarRej=false;


public pendenciasList: ListaDetalhePendenciaAprovacao[] = [];

And the model class ListaDetalhePendenciaAprovacao.model.ts is:

export class ListaDetalhePendenciaAprovacao {
  public codigoPendencia: number;
  public descricaoCedente: string;
  public descricaoSacado: string;
  public codigoTitulo: number;
  public dataVencimento: Date;
  public valorTitulo: number;
  public valorCorrecao: number;
  public valorCorrigido: number;
  public codigoAcao: number;
  public acaoTomada: string;
  public complementoAcao: string;
  public dataRegistroAcao?: Date;
  public acaoTomadaPor: string;
  public numeroTitulo: string;
  public atrasoPrioritario: boolean;
  public codigoOrigem: number;
  public idPendenciaTitulo?: number;
  public isSelected?: boolean

I've also been hving the same issue with array.findIndex(). I apologize for the atributes being in my native language, I don't think it should be an issue.

Thanks in advance!

Octavian Mărculescu

This is happening because of the curly braces in the callback that you pass to some. If you open the curly braces, then you need to return a boolean value from it:

let existeApr = this.pendenciasList.some(element =>{
  return !isUndefined(element.isSelected) && element.isSelected

But for a one liner like yours, you should drop the curly braces altogether and go with something like this:

let existeApr = this.pendenciasList.some(element =>
  !isUndefined(element.isSelected) && element.isSelected)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at


Login to comment


How to use .some() for all values in an array with different objects

How to use on array of objects to filter out some specific keys based on it's values?

Check if an array includes some objects

Sort Array of Objects With Some Conditions

How can I use .some() to find if an array of objects contains a specific property value

Cannot reorder an array of objects in JS

Cannot find object in an array of objects

Cannot sort array of objects in react

Swagger cannot create array of objects

Why Cannot I use java script method Sort() on Array objects created from jquery $.makeArray()

How to write query for condition of some objects must NOT be in array of objects and one of some other objects Must be in array of object?

Remove some properties from array of javascript objects

how to call destructor on some of the objects in a Dynamic Array

How to filter an array of objects, based on some fields?

Build an array of objects from some arrays

Merging some objects by iterating through an array

Move some objects of array at the end in swift 3

How to load some values to an instance of an array of objects?

Cannot use some type in function call

Cannot properly use the Makefile for some course files

Why i cannot use some svg in firefox?

Use switch case for array of objects

How to use localStorage on array of objects

How to use an array of objects in vb

Use $or with nested array of objects in mongodb

How to use objects in an array (php)?

how to use an array of objects in javascript

how to use explode for an array of objects

Get some objects from array of objects in a document (mongoose)