What's the meaning of “=>” in TypeScript? (Fat Arrow)

后端 未结 8 1884
心在旅途
心在旅途 2020-11-28 22:59

I just start to learn TypeScript, and I saw there is a lot of code using this sytax =>. I did some research by reading the Specification of TypeScript Versio

相关标签:
8条回答
  • 2020-11-28 23:54

    In a type position, => defines a function type where the arguments are to the left of the => and the return type is on the right. So callback: (result: string) => any means "callback is a parameter whose type is a function. That function takes one parameter called result of type string, and the return value of the function is of type any".

    For the expression-level construct, see What's the meaning of "=>" (an arrow formed from equals & greater than) in JavaScript?

    0 讨论(0)
  • 2020-11-28 23:54

    It is called a "fat arrow". It was added in EcmaScript6 and replaces the function keyword among other things.

    More can be read here.

    0 讨论(0)
提交回复
热议问题