How to specify the return type in a TypeScript arrow function?

Sometimes, we want to specify the return type in a TypeScript arrow function.

In this article, we’ll look at how to specify the return type in a TypeScript arrow function.

How to specify the return type in a TypeScript arrow function?

To specify the return type in a TypeScript arrow function, we put a colon and the type after between the signature and the arrow.

For instance, we write

const addTodo = (text: string): AddTodoAction => ({
  type: "ADD_TODO",
  text: text,
});

to make the addTodo function return an object with the AddTodoAction type.

Conclusion

To specify the return type in a TypeScript arrow function, we put a colon and the type after between the signature and the arrow.