Avatar ·

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

Hello everyone! I just started learning TypeScript and encountered a problem when working with enums. I have this code:\n\n```typescript\nenum Color {\n Red = 'RED',\n Green = 'GREEN',\n Blue = 'BLUE'\n}\n\n// I get a value from an external source (e.g., from an API)\nconst userInput: string = 'RED'; // or maybe 'YELLOW'\n\n// I need to check if userInput is a valid Color value\nif (userInput === Color.Red) {\n console.log('This is red');\n}\n```\n\nBut the problem is that if I get a value that is not in the enum (e.g., 'YELLOW'), I need to handle this situation correctly. I tried using `Object.values(Color).includes(userInput)`, but TypeScript complains that `userInput` has type `string`, not `Color`.\n\nPlease advise how to