generic return type typescript inheritance 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
function identity<T>(arg: T): T {
return arg;
}Try
Example 3: how to make a generic variable in javascript
var x = 1;
var y = 1;
if (x == y) {
x = x + 1
}