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 - TypeScript Tutorial
From the course: TypeScript Essential Training
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
-
-
-
-
Primitives and built-in types4m 29s
-
(Locked)
Creating custom types with interfaces6m 2s
-
(Locked)
Defining types using type aliases2m 14s
-
(Locked)
Defining enumerable types3m 30s
-
(Locked)
Typing functions3m 47s
-
(Locked)
Defining a metatype using generics6m 34s
-
(Locked)
Challenge: Types1m 5s
-
(Locked)
Solution: Types4m 31s
-
-
-
-
-