We already know that it is possible to explicitly declare the type of an element in our application by using optional type annotations:
function greetNamed(name: string): string {
return 'Hi! ${name}';
}
In the previous function, we specified the type of parameter name (string) and its return type (string). Sometimes, we will need to specify the types of the function, as opposed to specifying the types of its components (arguments or returned value). Let's look at an example:
let greetUnnamed: (name: string) => string;
greetUnnamed = function(name: string): string {
return 'Hi! ${name}';
};
In the preceding example, we have declared the greetUnnamed variable and its type. The greetUnnamed type is a function type that takes a string variable called name as its only parameter and returns a string after being invoked. After declaring the...