Interface for a function in TypeScript
An interface can be made not only for an object, but also for a function. To do this, the interface body specifies call signature functions: parameters for the function and their types, as well as the type of the function's result.
Let's look at the following example. Let's make a type using the IMathFunc interface. In parentheses, we specify two numeric parameters. We specify a boolean type for the return value:
interface IMathFunc {
(num1: number, num2: number): boolean;
}
Now let's make a function myFunc based on our interface:
let myFunc: IMathFunc = function(num1: number, num2: number): boolean {
if(num1 == num2) {
return true;
} else {
return false;
}
}
console.log(myFunc(2, 2));
Create an interface for a function that takes two strings as a parameter and returns these strings separated by a space.
Create an interface for a function that takes a number as a parameter and returns an array of divisors of that number.
Create an interface for a function that takes a string as a parameter and returns an array of words from that string.