Typing Functions - The Basics#
Functions are the backbone of code reusability. TypeScript makes it painless to add type annotations to functions and it empowers us to use the latest ECMAScript function capabilities, including default parameters, destructured arguments, and arrow functions.
Typing functions consists of two parts: typing the parameters and typing the return value. In the example below, our
toNumber function takes a string or number as a parameter and returns a number: