July 2018
Intermediate to advanced
420 pages
8h 46m
English
Generics are a very useful way of creating flexible classes and functions. They are very similar to those used in C#. It's very useful to be used in more than one place.
We can create generic functions by adding angle brackets after the function names and enclosing datatypes, as in the following example:
function genericFunction<T>( arg: T ): T [] { let myGenericArray: T[] = []; myGenericArray.push(arg); return myGenericArray;}Note that the t inside the angle brackets (<t>) means that genericFunction() is of the generic type.
Let's see this in practice:
function genericFunction<T>( arg: T ): T [] { let myGenericArray: T[] ...Read now
Unlock full access