I figure that out: One post in SO explain this: In TypeScript how do I declare an array of functions that accept a string and return a string?
it turns out:
A function type literal of the form
( ParamList ) => ReturnType
is exactly equivalent to the object type literal
{ ( ParamList ) : ReturnType }
So, Colon: with Bracket{} <=> Arrow =>
I am pretty new to Typescript, there is one example confuses me with its syntax:
var sayHello: (input: string) : string = function (s: string) {
return "Hello " + s;
}
var stringUtils: { (input: string): string; }[];
stringUtils.push(sayHello);
Could anyone help to give a little explanation what this code do? Especially what the first part definition does?
var sayHello: (input: string) : string = function (s: string) {
return "Hello " + s;
}
The example says sayHello is a function variable, but when I run it, I got "=>" expected error, does this mean this syntax belong to old typescript but not exist now?