How to assign number to the name Enum Typescript?

Asked

Viewed 108 times

0

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

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

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

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

      case "01":
        return "EXTRA";
    }   } }
  • You can post the Switch you made?

  • @Lucasbrogni, of course, added.

  • Where is the enum?

  • Enum I can’t create because I can’t add names like 00 and 01

  • @Victoroliveira I believe the problem is that you are not giving a break; no case.

1 answer

1


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";
     }   
} 
}
  • It would be interesting to comment on what is happening for the understanding of the colleague.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.