From the course: TypeScript Essential Training

Unlock the full course today

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

Defining a metatype using generics

Defining a metatype using generics - TypeScript Tutorial

From the course: TypeScript Essential Training

Defining a metatype using generics

- [Instructor] In the previous video, I showed you how to apply TypeScript typings to a functions parameter and return values. In this video, I'm going to show you how to take that syntax one step further with what might be considered TypeScripts most powerful feature, generics. A generic type is simply a meta type, a type that represents any other type that you might want to substitute in. It's easiest to understand the generic type and the power it brings by simply showing it in action. And that clone function from the previous video is a great candidate for generics. Let's take a look and see why. In the previous video, in order to give TypeScript enough information to be useful, I had to supply a specific input type and return type. In this case, the method accepts a contact parameter and returns a contact value. But if we take a look at the actual code in this function, there's nothing specific to a contact at all.…

Contents