An open API service indexing awesome lists of open source software.

https://github.com/shubhamd99/typescript-generics-example


https://github.com/shubhamd99/typescript-generics-example

javascript typescript typescript-generics

Last synced: 29 days ago
JSON representation

Awesome Lists containing this project

README

          

#### Typescript Generics
* TypeScript extends JavaScript by adding types to the language.
* TypeScript speeds up your development experience by catching errors and providing fixes before you even run your code.

* Sometimes you come across a situation to repeat the same block of code for different types. So, instead of writing repeated blocks of code, generics let you write a generalized form of method.

* i.e Functions, Interfaces, Classes
* Code that accepts type parameters for each instance or invocation.

#### Implements
* The new class can be treated as the same "shape", while it is not a child. It could be passed to any method where the Person is required, regardless of having different parent than Person

#### Extends
The new class is a child. It gets benefits coming with inheritance. It has all properties, methods as its parent. It can override some of these and implement new, but the parent stuff is already included.

![vscode](https://i.imgur.com/2NVleV3.png)

```
npx ts-node CompareTwoArrays.ts
```