2

sorry I am newbie in Typescript.

I have enum with String value like this

export enum NotificationType {
    GeneralInfo = "General Info",
    EventUpdate = "Event Update",
}

and I want to get that string value in a method. I have tried it like this

notifictionTypeToString(type: NotificationType) : string {
    
    if (type == NotificationType.EventUpdate) {
        return NotificationType[NotificationType.EventUpdate];
    } 
}

if I read the documentation about enum reverse mapping , I can access the string value like that, but I have an error

enter image description here

so how to get string value in enum ?

Alexa289
  • 8,089
  • 10
  • 74
  • 178
  • The documentation says "In addition to creating an object with property names for members, **numeric** enums members also get a reverse mapping from enum values to enum names." You have a string enum, not a numeric enums. String enums do not get such reverse mappings; you'll have to do it [yourself](https://stackoverflow.com/questions/54039138/how-to-handle-reverse-mapping-of-string-enums-with-different-string-literals-in). See [the answer](https://stackoverflow.com/a/54041614/2887218) to the question this duplicates; if I use that code here, it gives you [this](https://tsplay.dev/wO8RrN). – jcalz Aug 01 '21 at 03:12

0 Answers0