Value to check (can be any type)
Type predicate indicating if value is SecurityLevel
if (isSecurityLevel(userInput)) {
// TypeScript knows userInput is SecurityLevel here
const level: SecurityLevel = userInput;
console.log(`Valid security level: ${level}`);
}
isSecurityLevel('High') // true
isSecurityLevel('Invalid') // false
isSecurityLevel(123) // false
isSecurityLevel(null) // false
Check if a string is a valid security level
Type guard function that validates whether a value is a valid SecurityLevel. Useful for runtime type checking and validation of user input or API responses.