4 ms·
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
by glitchdout 8y ago
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%0A%20%20%20%20Red%20%3D%201%2C%20Green%20%3D%202%0D%0A%7D%0D%0A%0D%0A%2F%2F%20To%20String%0D%0A%20var%20green%3A%20string%20%3D%20Color%5BColor.Green%5D%3B%0D%0A%0D%0A%2F%2F%20To%20Enum%0D%0Avar%20color%20%3A%20Color%20%3D%20Color%5Bgreen%5D%3B%0D%0A%0D%0A 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.
- realusername 8y agoAh 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.