From the course: TypeScript Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Defining enumerable types

Defining enumerable types

- [Educator] When you write code, you'll often need to reference various kinds of hard-coded values. For instance, let's say that in our application a contact can also have a status value, which indicates the various states that a contact can be in, such as Active, Inactive, New, or otherwise. In order to add this property, I could define it as a string property, like this, which would allow me to assign the values I need, like this, like Active or Inactive. The problem with this approach is that the string type allows me to assign any string such as, or consider a more nefarious example. This one is a misspelling with a 1 instead of an I that would introduce a variety of bugs that would be very difficult to spot. Now, our fictitious company and our application may be concerned about happy customers and maybe we hope that as developers we never make typos, but I don't ever want to allow either of those two values to be…

Contents