shubhamd99 / typescript-generics-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

 npx ts-node CompareTwoArrays.ts

About


Languages

Language:TypeScript 100.0%