Function Types

This lesson covers a brief overview of function types to ensure you have a solid foundation before the introduction to generic functions.

Functions as values

Every value in TypeScript has a type. Since JavaScript is a functional language, this means that functions are values too. Therefore, they also have types.

The easiest way to check the type of a function is to assign it to a constant and hover over the constant inside the code editor.

Press + to interact
const add = (x: number, y: number) => x + y;

The type of add is inferred to be (x: number, y: number) => number. As you can see, it consists of a list of function parameters with their types and function return type, separated by an arrow symbol.

You can also define ...