113
rated 0 times
[
120]
[
7]
/ answers: 1 / hits: 27803
/ 4 Years ago, thu, july 9, 2020, 12:00:00
Enum definition:
enum Colors {
Red = "red",
Blue = "blue"
}
How can I cast some arbitrary sting (e.g. a result from a GET request) to the enum?
const color: Colors = "blue"; // Gives an error
In addition, why do integer enums work but string enums fail to have the same behavior?
enum Colors {
Red = 1,
Blue
}
const color: Colors = 1; // Works
More From » node.js