Course contentsShow
← TypeScript
Lesson 237 of 1,7966. FunctionsFree lesson

Arrow Function Type Annotations

Understand how to add type annotations to arrow functions and their special syntax considerations.

Arrow Function Type Annotations

What you'll learn: How to add types to arrow functions and handle their unique syntax quirks.

The Two Ways to Type an Arrow Function

Arrow functions are just like regular functions, but their type annotation syntax can go in two different places—and this confuses beginners constantly.

Approach 1: Annotate Inline (Like Regular Functions)

You can annotate each parameter and the return type directly in the arrow function:

const add = (x: number, y: number): number => {
  return x + y;
};

const greet = (name: string): string => `Hello, ${name}`;

Notice the return type : number and : string come before the arrow =>.

Approach 2: Annotate the Entire Function Type

You can also define the entire function's type upfront, then assign the arrow function to it:

const add: (x: number, y: number) => number = (x, y) => {
  return x + y;
};

Here, (x: number, y: number) => number is the function type (what you learned in "Function Type Syntax"). The arrow function on the right doesn't need inline annotations because TypeScript infers them from the type on the left through contextual typing.

Which Should You Use?

Inline annotations (Approach 1) are more common and feel natural. Type-first annotations (Approach 2) are useful when you're implementing a specific function signature or want to reuse the type.

Key Takeaway: Arrow functions can have types annotated inline (parameters and return) or by declaring the full function type first—both work, and TypeScript infers correctly in both cases.