Enums
Helps to define a set of named constants.
Numeric Enum
- The following members after Up are auto incremented.
enum Direction {
Up = 1,
Down,
Left,
Right
}
enum Direction {
Up,
Down,
Left,
Right
}
- By default, Up will be initialized as 0 and rest other members are auto incremented.
String Enums
enum Direction {
Up = "UP",
Down = "DOWN",
Left = "LEFT",
Right = "RIGHT"
}
- In string enums, each member has to be initialized.
enum types
- Enums can be used as types also (but constants can't).
enum CHART_TYPES {
LINE = 'line',
LINE_FILL = 'line_fill',
PIE = 'pie',
BAR = 'bar',
DOUGHNUT = 'doughnut'
}
let myChartType:CHART_TYPES;
- enums can be used in custom types (but constants can't be)
type chartType = CHART_TYPES.LINE | 2 | 3 ;
- Reference Links: