Type Inference
TypeScript infers the return type based on the return statement when the function body is a single expression.
Example: In this case, TypeScript infers that the return type is number
based on the multiplication operation.
const multiply = (a: number, b: number) => a * b;
console.log(multiply(5, 6)); // Output: 30
Output:
30
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