Gaurav
Gaurav

Reputation: 11

Arrow function and Inheritance in TypeScript

I am trying to learn TypeScript using Barasat Ali Syed's Deep Dive.

I came across below code in Arrow Functions and inheritance. Please help me understand what is the significance of second :string in this line "(b:string) : string"

class Adder {
    constructor(public a: number) {}
    // This function is now safe to pass around
    add = (b: string): string => {
        return this.a + b;
    }
}

Upvotes: 1

Views: 612

Answers (1)

Diullei
Diullei

Reputation: 12414

(b: string): string => { ... }

Is an anonymous arrow function. The second :string is a definition of the return type of this function.

On your Adder class, you are defining a property add and assigning an anonymous function that expect a string argument b parameter and return a string value.

Upvotes: 1

Related Questions