Enums in TypeScript are a way of representing a fixed set of named values. They can be defined using the keyword enum.

Enums can be defined with both string and numeric values. When an enum is defined with string values, the string value must be unique within the enum. When an enum is defined with numeric values, the numeric value does not have to be unique within the enum.

Enums can be used in various ways in TypeScript. One common use is to define a set of constants. For example, we could use an enum to represent the days of the week:

enum DaysOfTheWeek { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };

We could then use this enum like this:

let today = DaysOfTheWeek.Monday;
console.log("Today is " + today); // outputs "Today is Monday"

Enums can also be used in switch statements:

switch (today) {
  case DaysOfTheWeek.Monday:
    console.log("Today is Monday");
  case DaysOfTheWeek.Tuesday:
    console.log("Today is Tuesday");
    // ...

Enums can also be used in conjunction with the typeof operator to check the enum type of a variable:

let myEnum: DaysOfTheWeek = DaysOfTheWeek.Monday;

if (typeof myEnum === "string") {
// this will never execute because myEnum is always going to be of type DaysOfTheWeek