Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
checking empty property for array of objects

I wanted to check if there is a property in an array of objects that has a null value , if there is then return true.

Currently my issue is

This condition will always return 'false' since the types '{ type: any; startDate: string; endDate: string; annualRent: any; }' and 'string' have no overlap.ts(2367)

#current code for checking empty property

const hasEmptyRentSchedProperty = Object.values((this.proposedRentSchedule)).some((v => v === null || v === ""))

#object = this.proposedRentSchedule

[
    {
        "type": 0,
        "startDate": "2022-1-4",
        "endDate": "2022-1-19",
        "annualRent": "232"
    },
    {
        "type": 0,
        "startDate": "2022-1-20",
        "endDate": "2022-1-20",
        "annualRent": null
    }
]
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The reason you get that error is because you are getting the values of array whose type is { type: any; startDate: string; endDate: string; annualRent: any; } and not just string. In this case, how does a string comparison work? That's what Typescript points out.

var data = [
  {
    "type": 0,
    "startDate": "2022-1-4",
    "endDate": "2022-1-19",
    "annualRent": "232"
  },
  {
    "type": 0,
    "startDate": "2022-1-20",
    "endDate": "2022-1-20",
    "annualRent": null
  }
]

console.log(data.some(element => Object.values(element).some(val => val === null || val === "")))

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda