The enum object to validate against.
Optional
opt: Partial<ValidatorOptions>Optional configuration.
The property decorator function.
You can validate a property to an enum based on a number.
enum ReadWrite {
ReadOnly = 1,
ReadWrite = 2,
}
class Protocol {
@Enum(ReadWrite)
@Relation(PrimitiveSymbol.u8)
type: ReadWrite
}
Or based on a string.
enum ChunkType {
IEND = 'IEND',
IDAT = 'IDAT',
}
class Protocol {
@Enum(ChunkType)
@Count(4)
@Relation(PrimitiveSymbol.char)
type: ReadWrite
}
@Enum
decorator validates that the decorated property value belongs to a specified TypeScriptEnum
.This ensures that the value conforms to one of the keys or values defined in the provided
Enum
.