Function Declaration
You can specify the return type when declaring the function separately.
Example: You explicitly declare the function type before the assignment, specifying the return type.
const divide: (a: number, b: number) =>
number = (a, b) => {
return a / b;
};
console.log(divide(10, 2)); // Output: 5
Output:
5
How to Specify Return Type in TypeScript Arrow Functions ?
To Specify the return type in the TypeScript arrow function, we have multiple approaches. In this article, we are going to learn how to Specify the type in the TypeScript arrow function.
Below are the approaches used to Specify the return type in the TypeScript arrow function:
Table of Content
- Explicit Return Type Annotation
- Type Inference
- Function Declaration
- Interface with Function Signature
- Using Type Alias for Function Signature
Contact Us