From the course: TypeScript for Node.js Developers

Unlock the full course today

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

Generics in a Node.js project

Generics in a Node.js project

From the course: TypeScript for Node.js Developers

Start my 1-month free trial

Generics in a Node.js project

- [Instructor] Generics allows us to create a generic function or components that can be reusable across our application while maintaining some sort of type checking in these components. The way it works with generics is where we can define a function with the type open for passing any type upon using the function. So, let me demonstrate in the context of our application. We'll change the function we just created to demonstrate an example of generics. So, scroll down to the same spot where we actually created the interface earlier and what we'll do as opposed to use an interface, and feel free to delete or comment this particular code here. In my case I'm going to delete it, because we're not going use it anymore and what I'm going to do here is create a generic. So, let me comment this as so, and I'm going to use the function and then create name creator. and I'm going to use the function and then create name creator. And yes we're going to delete this one here. And then how you…

Contents