Enums

Enums are available only in TypeScript. On a few occasions, you may simply want to store a set of numbers, serially or not. Enums hand you a numeric data structure control without having to drag in the complexities of arrays or objects.

The following example shows an enum type with numbers from 0 to 2:

enum Status {Started, InProgress, Completed}let status:Status = Status.InProgress // 1

Enums are 0-based; therefore, Started holds 0, InProgress holds 1, and Completed holds 2. In addition, enums are flexible; hence, you can provide a number for the starting point instead of 0:

enum Status {Started = 1, InProgress, Completed}let status:Status = Status.InProgress // 2

You can write more expressive code with Enums. Let's see how, by using ...

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.