Concepts: Supporting current data types and supporting future data types
Generic <T> type variable
function identity<t> (arg:t): T {return
arg;
}
@Component ({
selector: ' App-root ',
templateurl: './app.component.html ',
styleurls: ['./ App.component.css ']
})
Export class Appcomponent implements OnInit {
ngoninit () {
//generics let output = IDE Ntity (' mystring ') can be without explicit generic type let
output = identity<string> (' mystring ');
Console.log (output);
}
Generic interface
Generic interface
interface GENERICIDENTITYFN {
<T>
}
//generic interface
identityfn<t> (arg:t): T { return
arg;
}
Ngoninit () {let
myidentity:genericidentityfn = THIS.IDENTITYFN;
Console.log (myidentity (' generic interface '));
}
Generic interface parameters
//generic interface parameter interface genericidentityparam<t> {(arg:t): T;}
Generic interface parameter identityparam<t> (arg:t): T {return arg;
} ngoninit () {Let identityparamslist:genericidentityparam<number> = identity; Console.log (identityparamslist);