July 2017
Intermediate to advanced
454 pages
10h 1m
English
We just saw how to define properties in interfaces. Similarly, we can also define function types in interfaces. We can define function types in interfaces by just giving the signature of the function with the return type. Note that, in the following code snippet, we have not added the function name:
interface AddCustomerFunc {
(firstName: string, lastName: string): string;
}
Now, we have AddCustomerFunc ready. Let's define an interface variable called AddCustomerFunc and assign a function of the same signature to it as follows:
var addCustomer: AddCustomerFunc; addCustomer = function(firstName: string, lastName: string) { console.log('Full Name: ' + firstName + ' ' + lastName); return firstName + ' ' + lastName; ...Read now
Unlock full access