Typescript makes our life much easier. It brings OOP concepts into javascript and helps us to write better code. Among other features that Typescript offers us, there’s a less familiar one — Generic types.

What exactly are Generics types? When and why should I use it?

The problem:

The most common feature in Typescript is, well, to defined types. let us take this simple code for example:

We’ve created a function called echo that gets an argument and returns it. This function can get all types, It will work if you pass a string, a number, an object, etc… So if we want to add some Typescript we can add the type ‘any’ so the compiler knows it can get all kinds of types.

#web-development #javascript #best-practices #typescript

Typescript Generics — Quick Intro
1.10 GEEK