Categories
TypeScript Answers

How to declare return types for functions in TypeScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *