How to declare return types for functions in TypeScript?

Sometimes, we want to declare return types for functions in TypeScript.

In this article, we’ll look at how to declare return types for functions in TypeScript.

How to declare return types for functions in TypeScript?

To declare return types for functions in TypeScript, we put it near the function signature.

For instance, we write

const sum = (a: number, b: number): number => a + b;

to make the sum function to return a value with the number type.

Conclusion

To declare return types for functions in TypeScript, we put it near the function signature.