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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ganesan CPosted Aug 10, 2021, 9:01 AM
Pranam BhatPosted Jun 7, 2021, 7:04 AM
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