Option is essentially an Object.
This is how it is defined when compiled to JS:
var Option;
(function (Option) {
Option["All"] = "all";
Option["Mine"] = "mine";
})(Option || (Option = {}));
You can use Object.keys() or Object.values() to be able to convert an Object to an array.
Thus, in order to make first = 'All', you can use:
enum Option {
All = "all",
Mine = "mine",
}
const first = Object.keys(Option)[0];
console.log(first)
If you want to play around with how things look between TS and JS, you can use the TS Playground. I've loaded this link in with the code I showed here.
If you want the firstValue to be of type Option, use Object.values(Option)[0]
.
Typescript playground seems to have an issue with the name Option
, so if you change it to Options
, it shows correctly that first is of type Options
: Playground
enum Options {
All = "all",
Mine = "mine",
}
const first = Object.values(Options)[0];
console.log(first) // 'all' of type Options
My local environment doesn't show that same weirdness.