July 2017
Intermediate to advanced
384 pages
8h 23m
English
Parameters and return values in the function signature can be typed too. Types protects you against JavaScript errors during function execution because the compiler warns you punctually at build time when the wrong types are used:
function add(x: number, y: number): number { return x + y;}
Function type is a way to declare the type of a function. To explicitly declare a function type, you should use the keywords var or let, a variable name, a colon, a parameter list, a fat arrow =>, and the function's return type:
var fetchName: (division: Division, customer: Customer) => string;
Now, you must provide an implementation of this declaration:
fetchName = function (division: Division, customer: Customer): string { // do something ...Read now
Unlock full access