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:

typescriptinterface IFunc {
  <T> (data: T): T;
}

Next, we declare the function myFunc and write the code in its body:

typescriptfunction 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:

typescriptlet func: IFunc = myFunc;

The full code will look like this:

typescriptinterface 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:

typescript'abcde'