Reading "enum" in typescript, I see that this code is compiled in javascript.
var Season = [];
Season[Season["Spring"] = 0] = "Spring";
Season[Season["Summer"] = 1] = "Summer";
Season[Season["Fall"] = 2] = "Fall";
Season[Season["Winter"] = 3] = "Winter";
console.log(Season.Spring);
console.log(Season[0]);
and if I change the season to {} an empty objext in the first line, this also works, and that makes sense. I do not know what's happening. What is it?
Edit: Yes. This is not what the compiler generates. The compiler uses an empty object. But if I changed it to an empty array. It still works. My question was why the array also works well. At first, my question included both versions, but someone edited the question and deleted the version of using the object.
source
share