I am completely new to typescript and have never met in C # or java before. Therefore, even if I read the instructions on the official typescript website, I really do not understand the real use Generics.
Here is a simple example Generics. What are the real benefits of this below?
function identity<T>(arg: T): T {
return arg;
}
var output = identity<string>("myString");
without Generics, I can just do it below (or I can use interfaces to pass the specified arguments.)
function identity(arg: any): any {
return arg;
}
var output = identity("myString");
Any advice would be appreciated. thank you
source
share