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
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?
It is called a "fat arrow". It was added in EcmaScript6 and replaces the function keyword among other things.
More can be read here.