generic function type typescript code example
Example 1: extend generics in functions typescript
interface Lengthwise {
length: number;
}
function loggingIdentity<T extends Lengthwise>(arg: T): T {
console.log(arg.length); // Now we know it has a .length property, so no more error
return arg;
}
Example 2: typescript generic type interface
interface IProcessor<T>
{
result:T;
process(a: T, b: T) => T;
}