Avatar ·

How to check if a value exists in an enum in TypeScript?

Hi! I'm new to TypeScript and encountered a problem when working with enums. I have this enum: ```typescript enum UserRole { Admin = 'admin', User = 'user', Guest = 'guest' } ``` I need to check if a string received from an API (e.g., 'moderator') is a valid value of this enum. I tried using `Object.values(UserRole).includes(value)`, but TypeScript complains that includes doesn't work with enums. I also tried `value in UserRole`, but that checks keys, not values. In JavaScript, I could just use `Object.values(...)`, but in TypeScript it's more complicated due to types. Please advise how to correctly and type-safely check if a string is one of the enum values? Preferably with a code example.