Last active
June 1, 2018 09:37
-
-
Save vreality64/73805500c8f8942061279d9fa67d9602 to your computer and use it in GitHub Desktop.
Typescript const enum vs enum ([email protected])
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Declare | |
const enum CommandType { | |
FOO = 1, | |
BAR = 2 | |
}; | |
// Usage | |
const commandType = CommandType.FOO | |
// Transpiled (inlining) | |
var commandType = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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