How can i set enum display name in Typescript?

As of TypeScript 2.4 you can assign string values directly to enum members

enum RoleTypes{
  None = "None",
  Admin = "Administrator",
  SuperAdmin = "Super Administrator"
}

Also see here


Yes, simply create an alias using a quoted identifier

enum RoleTypes {
 None,
 Admin,
 SuperAdmin,
 'Super Administrator' = SuperAdmin 
}

You can use a seperate object or array for this (Playground):

enum RoleTypes {
    None,
    Admin,
    SuperAdmin
}

let RoleTypesDisplay: { [index: number]: string } = {};
RoleTypesDisplay[RoleTypes.None] = "None";
RoleTypesDisplay[RoleTypes.Admin] = "Administrator";
RoleTypesDisplay[RoleTypes.SuperAdmin] = "Super Administrator";

var roleName = RoleTypesDisplay[RoleTypes.SuperAdmin];
alert(roleName);

// because RoleTypes is a number based enum that starts with 0 this is equals to 
RoleTypesDisplay = ["None", "Administrator", "Super Administrator"];

var roleName = RoleTypesDisplay[RoleTypes.SuperAdmin];
alert(roleName);