February 2019
Beginner
694 pages
18h 4m
English
Enums are a special type that has been borrowed from other languages such as C#, C++, and Java, and provides a solution to the problem of special numbers. An enum associates a human-readable name for a specific number. Consider the following code:
enum DoorState {
Open,
Closed,
Ajar
}
Here, we have defined an enum called DoorState to represent the state of a door. Valid values for this door state are Open, Closed, or Ajar. Under the hood (in the generated JavaScript), TypeScript will assign a numeric value to each of these human-readable enum values. In this example, the enum value DoorState.Open will equate to a numeric value of 0. Likewise, the enum value DoorState.Closed will equate to the numeric value of 1, and the enum value ...
Read now
Unlock full access