Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!