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
- Host: GitHub
- URL: https://github.com/shubhamd99/typescript-generics-example
- Owner: shubhamd99
- Created: 2020-04-04T10:20:58.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-25T05:20:57.000Z (over 5 years ago)
- Last Synced: 2025-10-30T22:44:32.047Z (8 months ago)
- Topics: javascript, typescript, typescript-generics
- Language: TypeScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.

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