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

217
Visualizações
Map Function - Unhandled JS Exception: TypeError: undefined is not an object evaluating map

I have a file called displayKeyHelpers.ts and the members.map code is on line 118. The code works for most users and in QA as well but occasionally it seems members is undefined. I am looking at a crash report that says

displayKeyHelpers.ts, line 118
SIGABRT: Unhandled JS Exception: TypeError: undefined is not an object (evaluating 'n.map') This error is located at: in V in Unknown in Unknown in Unknown..

It seems like members in the function below is undefined. How can I add a check?

export const memberDropdownOptions = (members: any): Option[] => {
  const options: Option[] = []
  members.map((member: Person) => {
    options.push({
      label: `${member.firstName} ${member.lastName}`,
      value: member.dependentNumber,
    })
  })
  return options
}

This is what I tried but it failed some unit tests so I am guessing that it is not right:

export const memberDropdownOptions = (members: Person[]): Option[] => {
  const options: Option[] = []
  members?.map((member: Person) => {
    options.push({
      label: `${member?.firstName} ${member?.lastName}`,
      value: member?.dependentNumber,
    })
  })
  return options
}

The function is used like this:

const memberOptions = memberDropdownOptions(members)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The members argument that you are passing to memberDropdownOptions(members) is not defined when the function is being called.

Is members relying on some asynchronous logic to be given a value? Trace back to where it's being assigned a value, and make sure memberDropdownOptions() only fires once it does have one.

about 4 years ago · Juan Pablo Isaza 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