Is there a way to dynamically generate enums in TypeScript?
I want to generate enum object dynamically from the API output, is this possible?
Is there a way to dynamically generate enums in TypeScript?
I want to generate enum object dynamically from the API output, is this possible?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pranam BhatRank #500 · 4.9K reputationPosted Jun 7, 2021, 3:04 AM EDT
No. TypeScript copmiler won't support this.
You can dynamically access enum in typescript by key like this:
https://stackoverflow.com/questions/50417254/dynamically-access-enum-in-typescript-by-key
Also, check this out
https://www.typescriptlang.org/docs/handbook/enums.html
https://medium.com/jspoint/typescript-enums-af03567d662
Ganesan CRank #369 · 6.8K reputationPosted Aug 10, 2021, 5:01 AM EDT