From the course: TypeScript Essential Training

Unlock the full course today

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

Creating custom types with interfaces

Creating custom types with interfaces - TypeScript Tutorial

From the course: TypeScript Essential Training

Creating custom types with interfaces

- [Instructor] Now that I've shown you the syntax to tell TypeScript about primitive and built-in types it's time to define our own custom type using what TypeScript calls an interface. The syntax to define an interface is pretty straightforward, just the keyword interface, followed by the name of the interface, I'll call this one Contact, followed by open and closed braces. Then inside these braces we can begin adding the properties that we want this interface to have. For example, let's say a contact should have an ID field with a type of number, a name with a type of string, and a birth-date field with a type of date. Now, if you're familiar with the more recent versions of JavaScript and the class syntax this might look incredibly familiar. In fact, any class definitions created using the JavaScript syntax can also be used as interfaces. The biggest difference between an interface and a class however, is that interfaces…

Contents