I have a string enum and need to check if a literal pertains to the enum. Reverse mapping does not work on string enums.
Supposing
enum Animals{
cat="c";
dog="d";
fish="f";
}
let animal= "d";
is animal a member of Animals ? Considering the enum an object you can iterate and check:
function inEnum(what, enu):boolean{
for (let item in enu){
if (enu[item]==what){
return true;
}
}
return false;
}
Is there a better way?, may this technique break in future versions?