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 after the colon and before the function body.
For instance, we write
const sum = (a: number, b: number): number => a + b;
to set the return type of the sum
to number
with : number
before the function body.
Conclusion
To declare return types for functions in TypeScript, we put it after the colon and before the function body.