Skip to content

Instantly share code, notes, and snippets.

@vreality64
Last active June 1, 2018 09:37
Show Gist options
  • Save vreality64/73805500c8f8942061279d9fa67d9602 to your computer and use it in GitHub Desktop.
Save vreality64/73805500c8f8942061279d9fa67d9602 to your computer and use it in GitHub Desktop.
Typescript const enum vs enum ([email protected])
// Declare
const enum CommandType {
FOO = 1,
BAR = 2
};
// Usage
const commandType = CommandType.FOO
// Transpiled (inlining)
var commandType = 1
// Declare
enum CommandType {
FOO = 1,
BAR = 2
};
// Usage
const commandType = CommandType.FOO
// Transpiled (still referenced)
var commandType = CommandType.FOO
// Behind the schenes
var CommandType;
(function (CommandType) {
CommandType[CommandType["FOO"] = 1] = "FOO";
CommandType[CommandType["BAR"] = 2] = "BAR";
})(CommandType = {}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment