1. Select TypeScript in the JavaSCript pane
  2. Open devtools console
  3. Paste this simple snippet and run:

const y = ['abc'];y.map((item) => item.toUpperCase());

What am I doing wrong around the arrow function that I am seeing "Unexpected identifier" errors?

1

Best Answer


Depending on your browser, there is nothing in that example that couldn't in theory work. For example, I'm running the latest version of Firefox and this example works as expected (treating the code as plain JavaScript).

const y = ['abc'];const result = y.map((item) => item.toUpperCase());console.log(result);

However, not all browsers are equal at the time of writing, so you might want to down-level compile it all to something older... this version should work in all browsers, and it the output from the TypeScript compiler.

var y = ['abc'];var result = y.map(function (item) { return item.toUpperCase(); });console.log(result);