Skip to content

Instantly share code, notes, and snippets.

@hoangtranson
Created May 9, 2019 03:57
Show Gist options
  • Save hoangtranson/b97ba4bc14d12c64f936c225c2f2e6cf to your computer and use it in GitHub Desktop.
Save hoangtranson/b97ba4bc14d12c64f936c225c2f2e6cf to your computer and use it in GitHub Desktop.
Number Enums and Strings
var Tristate;
(function (Tristate) {
Tristate[Tristate["False"] = 0] = "False";
Tristate[Tristate["True"] = 1] = "True";
Tristate[Tristate["Unknown"] = 2] = "Unknown";
})(Tristate || (Tristate = {}));
enum Tristate {
False,
True,
Unknown
}
console.log(Tristate[0]); // "False"
console.log(Tristate["False"]); // 0
console.log(Tristate[Tristate.False]); // "False" because `Tristate.False == 0`
@hoangtranson
Copy link
Author

So when I type Tristate this will return {0: "False", 1: "True", 2: "Unknown", False: 0, True: 1, Unknown: 2}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment