Function Signatures and the void Keyword
Learn how to use type annotations in TypeScript to strongly type function signatures.
We'll cover the following...
Function signatures in TypeScript
One of the best features of using type annotations in TypeScript is that they can also be used to strongly type function signatures.
To explore this feature a little further, let’s write a JavaScript function to perform a calculation as follows:
// This function calculates the result of (a * b) + cfunction calculate(a, b, c) {// Return the result of (a * b) + creturn (a * b) + c;}// Log the result of calling the calculate function with arguments 3, 2 and 1console.log("calculate() = " + calculate(3, 2, 1));
Calculate function with numbers
Here, we have defined a JavaScript function named calculate
from lines 2 — 6 that has three parameters, a
, b
, and c
.
Within this function, we are multiplying a
and b
, and then adding the value of c
.
The result is correct, as ...