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

181
Views
TypeScript: compare two enums by string

I have 2 enums:

enum Insurer {
  PREMERA = 'premera_blue_cross',
  UHC = 'united_health_care'
}

enum ProductSource {
  PremeraBlueCross = 'premera_blue_cross',
  UnitedHealthCare = 'united_health_care'
}

I try check if array of Insurer includes ProductSource:

const insurerArr: Insurer[] = [Insurer.PREMERA, Insurer.UHC]
insurerArr.includes(ProductSource.PremeraBlueCross)

But got an error from the TS compiler:

Argument of type 'ProductSource' is not assignable to parameter of type 'Insurer'.

There is a way to compare without do a casting to string and then to the other enum?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You may want to consider to switch to type instead of enum:

type Insurer = 'premera_blue_cross' | 'united_health_care';
type ProductSource = 'premera_blue_cross' | 'united_health_care';
const insurerArr: Insurer[] = ['premera_blue_cross', 'united_health_care'];
insurerArr.includes('premera_blue_cross');
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!