From the course: TypeScript Essential Training
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Solution: Types - TypeScript Tutorial
From the course: TypeScript Essential Training
Solution: Types
(upbeat music) - [Instructor] In this challenge, I showed you a JavaScript application that had just been converted to TypeScript but lacked any kind of additional type information. And I asked you to give it that type information. Here's how I solved this challenge. First, I asked you to create an interface to describe the structure of this variable on lines one through five. The way I would approach this is, first, come up with a name. What are we looking at here? It's an array of to-do items. So I'm going to call my interface something like to-do item or just to-do. Next, I'm going to take a look at what is similar and what is different in these items. They all have an ID that's a number, a title that's a string, and a status that's also a string. Also, one of them has a completed on property, which is a date value, however, this is not always present on all to-do items. So I'll make this one optional. Then,…
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
-
-
-
-
-