unacy / validateEnum
Function: validateEnum()
function validateEnum(value): value is EnumType;Defined in: packages/core/src/utils/validation.ts:102
Validate that a runtime value is a valid TypeScript enum object.
Accepts numeric enums (with reverse-mapped keys filtered out) and string enums. Rejects empty objects and mixed enums whose forward entries contain both string and number values.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to validate |
Returns
value is EnumType
true if value is a valid EnumType
Throws
If the enum contains both numeric and string members
Example
enum LogLevel { DEBUG = 0, INFO = 1 }
validateEnum(LogLevel); // true
validateEnum({}); // falseUse When
You are receiving a runtime value and need to confirm it is a valid TypeScript enum before using it as a TypedMetadata<EnumType>.type field.
Pitfalls
NEVER use validateEnum to check plain objects that happen to have string values — they may look like string enums but carry no semantic meaning. Use validateRecordSchema for plain data objects.