Why it is not possible to do in ts something like this:
var stringArray: string[] = ["a", "b", "c"];
stringArray.map(str: string => console.log(str));
var stringArray: string[] = ["a", "b", "c"];
stringArray.map(str: string => console.log(str));
Actually you can, you just need to take it into brackets:
stringArray.map((str: string) => console.log(str));
but in fact you can omit type declaration, because of type inference compiler already knows that str
is a type of string
:
stringArray.map(str => console.log(str));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With