From the course: Learning TypeScript

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Defining custom types with interfaces

Defining custom types with interfaces - TypeScript Tutorial

From the course: Learning TypeScript

Start my 1-month free trial

Defining custom types with interfaces

- [Instructor] In the previous chapter, I gave you an overview of the syntax that TypeScript uses in order to apply type information to variables and functions. At the end, I even showed you how to describe the structure of complex types using the bracket syntax shown here. While this syntax is perfectly legal, and sometimes even useful, there is a better way to represent complex object structures like this, and that is with interfaces. To demonstrate, I'll convert this inline type into an interface. To create an interface, I'll simply use the keyword, interface, followed by the name of the interface that I'd like to create. In this situation, the type I've defined as the return value of the git inventory item function, actually describes an inventory item in my application. So I'm going to call my interface, Inventory Item, followed by opening and closing braces. That's all you need to do in order to define an interface,…

Contents