Functions
TypeScript adds some new capabilities to the standard JavaScript functions to make them easier to work with.
TypeScript functions can be created in the same way as JavaScript functions—either as a named functions or as anonymous functions. For example:
If we leave our function unannotated, TypeScript will implicitly assign the type any
to the parameter types and the return type. So the above example would be typed as:
However, as we know, that's not good enough! We want to enforce the types that go into and out of our function. In the next section we will add types to our function signatures to achieve this.
Last updated