Search⌘ K

Function Types

Explore the concept of function types in TypeScript within generics. Understand how to type functions and callbacks, use higher-order functions, and apply these skills for safer and more expressive type annotations.

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.

TypeScript 3.3.4
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 ...