I want to transform this code:
var formatQuoteAmount = function (tx) { return Currency.toSmallestSubunit(tx.usd, 'USD'); }; var quoteAmounts = res.transactions.map(formatQuoteAmount);
into an anonymous arrow function. I've written this:
var quoteAmounts = res.transactions.map(tx => Currency.toSmallestSubunit(tx.usd, 'USD'));
I get expression expected
syntax error at the arrow. I looked up the default syntax here and seems like the syntax of my code is correct. Any ideas what the problem might be?
I have it working with this syntax:
var quoteAmounts = res.transactions.map(function (tx) { return Currency.toSmallestSubunit(tx.usd, 'USD') });
but I want to make it a one-liner, with an arrow-function.
Running on node v5.3.0
An arrow function looks similar to a function expression — it's just shorter. Again we assign an anonymous function to a named variable. The syntax of the arrow function consists of zero or more parameters , an arrow => and then concludes with the function statements .
The "Expression expected" TypeScript error occurs when we have a syntax error in our code or our code editor is using an older version of TypeScript. To solve the error, make sure to correct and syntax errors and use a recent version of the TypeScript compiler.
Arrow function syntax is wonderful syntactic sugar that removed the need for the following: the return keyword (for one line functions)
An Arrow function should not be used as methods. An arrow function can not be used as constructors. An arrow function can not use yield within its body. Arrow function cannot be suitable for call apply and bind methods.
I had the error expression expected
reported by Webstorm when editing a Node.js program. In this case the solution is to set the language version to a version that supports this feature.
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