November 2019
Beginner
804 pages
20h 1m
English
Numerical enums are the simplest way to define enumerations (or enums) in TypeScript. Each entry in such an enum simply associates a logical name with a numerical value.
The following is a basic example of a numerical enum:
enum VehicleType {
Car,
Bus,
Train
}
let myVehicleType = VehicleType.Car;
console.log("My vehicle type: ", myVehicleType);
And the following is the corresponding output:
$ node ts-enums-01.js My vehicle type: 0
As you can see, in their basic form, enum entries map to unsigned integer values that start at 0.
Read now
Unlock full access