How to assign number to the enum TypeScript name?

0

All right, guys? Can anyone help me with this problem in TypeScript 2.3.

Problem: My backend sends me a property in Json with value 00 or 01, I need to convert to Regular or Extra. But I can not assign numbers in the Enum name, I already tried to make a switch inside the get method but nothing worked, could anyone help me?

export class Viagem {   tipoViagem: string;   descViagem: string;

  public get $descViagem(): string {
    switch (this.tipoViagem) {
      case "00":
        return "REGULAR";

      case "01":
        return "EXTRA";
    }   } }
    
asked by anonymous 13.08.2018 / 16:14

1 answer

0
export class Viagem {   
    tipoViagem: string;    
    descViagem: string;

  public get $descViagem(): string {
    if (this.tipoViagem == "00") {
        return "REGULAR";
     }
     else
     if (this.tipoViagem == "01"){
        return "EXTRA";
     }
     else{
        return "ERRO";
     }   
} 
}
    
05.09.2018 / 21:39