Tuesday, March 14, 2017

how to compare enum values to strings in TypeScript

Both of these alerts will go off!

enum ColorPattern {
   Solid,
   Splotchy,
   Striped
}
if (ColorPattern.Solid == ColorPattern["Solid"]) {
   alert("equals");
}
if (ColorPattern.Solid === ColorPattern["Solid"]) {
   alert("strictly equals");
}

No comments:

Post a Comment