Hacker News new | ask | show | jobs
by nine_k 674 days ago
Certainly so! The first example is needlessly contrived.

But instead of

  for (const i=0; i < data.length; i++) {
    new_data[i] = old_data[i].toUpperCase();
  }
you can write

  const new_data = old_data.map((x) => x.toUpperCase());
I think it's both more clear and less error-prone.
1 comments

The second code does not compile and introduces a new dependency.
Sorry, are we speaking about the same language?

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCA2ATA...

My apologies, I thought it was C++. I should learn typescript, it is one of those I'm postponing.
Nothing in that snippet is Typescript-specific, it's just plain Javascript.

All syntactically valid Javascript is also syntactically valid Typescript, it just adds stuff, though you can get runtime errors for things like reassigning variables in a way Javascript is fine with that Typescript disallows.