Enum as a type in TypeScript

Each enumeration creates its own data type. Let's assign the type Season to a variable storing the current season:

typescriptlet current: Season;

Let's write the season number into our variable:

typescriptlet current: Season = Season.Winter;
console.log(current); // 0

You can specify the season number manually:

typescriptlet current: Season = 3;

But if you try to write data of a different type, for example, a string, you will get an error:

typescriptlet current: Season = 'str'; // there will be an error

Unfortunately, the range of values ​​is not tracked and you can write down a number that is not in our list:

typescriptlet current: Season = 7; // there will be no error

When checked using the typeof operator, our variable will return a numeric type:

typescriptlet current: Season = 3;
console.log(typeof current); // "number"

To sum it up, we can say that this type is not checked very strictly and therefore its value is questionable.