Here is the JavaScript code for that logic:
// Fruit.js
var Fruit;
(function (Fruit) {
Fruit[Fruit["APPLE"] = 0] = "APPLE";
Fruit[Fruit["ORANGE"] = 1] = "ORANGE";
})(Fruit || (Fruit = {}));
// main.js
var bowl = [Fruit.APPLE, Fruit.ORANGE];
console.log(bowl);
If you wish to optimize, consider using a const enum
:
const enum Fruit {APPLE, ORANGE};
This approach will directly inline the values of the enum in the JavaScript code:
// Fruit.js: no content, as the values are directly used in main.js
// main.js
var bowl = [0 /* APPLE */, 1 /* ORANGE */];
console.log(bowl);
Using a const enum
eliminates unnecessary JS generated from regular enums.