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

188
Visualizações
Checking Typescript Enum for value results in TS error OR doesn't work

The following code does what I want it to do:

BallStatusTypes.safe === BallStatusTypes[status] ? 'ball' : 'ball-danger'

Despite giving me this error: This condition will always return 'false' since the types 'BallStatusTypes' and 'string' have no overlap.

The following, error free code does NOT do what I want it to do:

status === BallStatusTypes.safe ? 'ball' : 'ball-danger'

The enum is:

export enum BallStatusTypes {
  danger = 1,
  safe = 2
}

How can I fix my code so that it does what I want it to do, without errors?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I ended up resolving this with:

export enum BallStatusTypes {
  danger = 'danger',
  safe = 'safe'
}

It seems I was having issues with the way enums create objects mapping to either a number or a string. And, typescript was unaware (when performing expressions on said value) of weather or not it should be comparing the numerical version or the string version of the status.

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