Interface with Function Signature
An interface defines a function signature, and you use it to declare the arrow function.
Example: An interface defines a function signature, and you use it to declare the arrow function.
interface MathOperation {
(a: number, b: number): number;
}
const subtract: MathOperation = (a, b) => a - b;
console.log(subtract(8, 3)); // 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