Reputation: 11
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
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