According to TypeScript documentation:
Enums allow us to define a set of named constants
i.e. enum is not a limited set of options, it's just a list of constants.
The code from your question:
const enum Mode{
Add=1,
Edit=22
}
let currentMode:Mode=222222;
let add: Mode = Mode.Add
will be compiled to the following JavaScript:
"use strict";
let currentMode = 222222;
let add = 1 /* Add */;
As you can see there won't be any object created for your const enum
in JS. TypeScript compiler will place used enum's values at the places of usages instead.
As for the enum type in C#. You can do the same thing. Code listed below is valid C# code:
public enum Mode
{
Add = 1,
Edit = 2
}
...
Mode mode = (Mode)123;