Hacker News new | ask | show | jobs
by realusername 2823 days ago
Unlike CoffeeScript, you can't have any technical debt with TypeScript, if one day TypeScript disapears, you just remove the types and you have a perfectly working JS file.
1 comments

Really? This isn't even close to valid JS.

enum Color { red = 1, green = 2, blue = 4 }

namespace Color { export function mixColor(colorName: string) { if (colorName == "yellow") { return Color.red + Color.green; } else if (colorName == "white") { return Color.red + Color.green + Color.blue; } else if (colorName == "magenta") { return Color.red + Color.blue; } else if (colorName == "cyan") { return Color.green + Color.blue; } } }

* Edited with a better example.

enums are probably the only TS thing which does not exist in plain JS (at least I can't think of any other one), and it's quite easy to replace. In your example you just replace enum by a hashmap and remove all the types and it's a valid JS file, it's not really that different. It would be quite easy for an automated tool to do that.
It's not that simple because you can reverse lookup a TS enum. So:

    enum Color { Red = 1, Green = 2 }
would be the same as:

    var Color = {
      Red: 1,
      1: 'Red',
      Green: 2,
      2: 'Green'
    }
See for yourself: https://www.typescriptlang.org/play/#src=enum%20Color%7B%0D%...

But I agree with you, it would be quite easy for an automated tool to replace a TS enum with pure JS.

Ah that's a good point, thanks for bringing it. I did know TS enums supported that, I thought it was just some syntax sugar for a hashmap.