To convert Enum to String in TypeScript, you can use the “bracket notation ([ ])” to access a specific value on the enum to get its name.
In TypeScript, an enum is a type used to define a set of named constants. By default, the numeric values of the enum members start from 0 and increment by 1.
Given an enum value, you can directly get its string representation.
Using bracket notation
enum Colors {
Red,
Green,
Blue
}
let color: Colors = Colors.Red;
console.log(Colors[color]);
Output
Red
Converting a Numeric enum to a string
If you have a numeric enum and you want to convert one of its values to a string representation, you can use the enum itself as a kind of lookup.
enum Days {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
console.log(Days[3]);
console.log(Days[Days.Wednesday]);
Output
Converting a Numeric enum to a number
To convert a numeric enum to a number, “access a specific property using dot notation.”
enum Days {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
const num = Days.Wednesday;
console.log(num);
console.log(typeof num);
Output
3
number
Converting a string enum to a string
To convert a string enum to a string, access one of the names in the enum using “dot notation.”
enum Days {
Sunday = 'S',
Monday = 'M',
Tuesday = 'T',
Wednesday = 'W',
Thursday = 'T',
Friday = 'F',
Saturday = 'S'
}
const str = Days.Wednesday;
console.log(str);
console.log(typeof str);
Output
The Object.keys() method returns an array containing the enum’s names and values, so you have to use the filter method to filter out the unnecessary values.
That’s it!
Related posts

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.