Answer the question
In order to leave comments, you need to log in
What is the meaning of enum type in typescript?
enum Color {Red, Green, Blue}
let c: Color = Color.Green;
As I understand it, Color.Green can also be accessed from an arbitrary place in the code, and not only in the value assigned to a variable with type Color. (Or is it not?)
If so, why is the type specification necessary? Where can enum be used at all?
Answer the question
In order to leave comments, you need to log in
The point is that an enum is used to store a limited set of values. What these values are depends on the context of your business logic.
These can be days of the week, a list of document statuses, and any other lists.
Why use an integer type for this when you can get away with an abstract set of numeric values or strings? Well, because the goal of one programmer is to write understandable and logical code. And the goal of his partner is to easily support the solution, and not puzzle over what kind of status list {0, 1, 2, ..., N} is there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question