Generic Type Interface in TypeScript
Now let's move on to the description of the generic type interface for calling the function. Let's define the function call signature in it:
interface IFunc {
<T> (data: T): T;
}
Next, we declare the function myFunc and write the code in its body:
function myFunc <T> (data: T): T {
return data;
}
let func: IFunc = myFunc;
Then we write a variable func, whose type refers to IFunc. And the variable itself calls the function myFunc:
let func: IFunc = myFunc;
The full code will look like this:
interface IFunc {
<T> (data: T): T;
}
function myFunc <T> (data: T): T {
return data;
}
let func: IFunc = myFunc;
console.log(func('abcde'));
After running the code we will see:
'abcde'