Alexander Solonik
Alexander Solonik

Reputation: 10230

Flow understanding A type based on another type

I was going throgh the flow documentation ( HERE ) and came across the following lines of code:

function identity<T>(value: T): T {
  return value;
}

The above code is used to illustrate an example for A type based on another type. I don't quite understand the usage and how would this be practically applicable, can somebody please shed some light on this with a practical/real life example.

Upvotes: 0

Views: 48

Answers (1)

Manoz
Manoz

Reputation: 6587

These are Generics.

So if you compile that code in javascript it would look something like

function identity(arg) {
    return arg;
}

So basically when you pass an argument to this function it will return you the value of same type.

From above link

enter image description here

Upvotes: 2

Related Questions