Reputation: 165
I'm confused about what the difference between these two the following types of a dummy arrow function. Can someone please point out the difference?
const hello = (i: string):string => { return "Hi, User!" }
and
const hello: string = (i: string) => { return "Hi, User!" }
Upvotes: 1
Views: 48
Reputation: 505
second function throw error!
[yours]
1. const hello = (i: string):string => { return "Hi, User!" } // correct
2. const hello: string = (i: string) => { return "Hi, User!" } // error
Because hello function type is not string.
hello function type is "(i: string) => string".
[correct]
const hello: (i:string) => string = (i: string) => { return "Hi, User!" }
Upvotes: 2