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

100
Views
typescript limit type to enum only

I have the following code:

enum MY_ENUM {
    A,
    B,
    C
}

type MY_TYPE = {
    field: MY_ENUM
}

// Error: Type '{ field: string; }[]' is not assignable to type 'MY_TYPE[]'.
const myArray: MY_TYPE[] = Object.keys(MY_ENUM).map(key => {
    return {
        field: key,  // key is a string, but I want it to be MY_ENUM
    }
})

It gives an error on myArray, saying string is not assignable to type 'MY_TYPE'.`, so how do I get the enum typed key instead of string? Or in another word, how can I iterate enum, gets the actual enum typed key but not its string representation?

example

about 4 years ago · Santiago Gelvez
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!