• @Enum decorator validates that the decorated property value belongs to a specified TypeScript Enum.

    This ensures that the value conforms to one of the keys or values defined in the provided Enum.

    Type Parameters

    • This

      The type of the class the decorator is applied to.

    • Value

      The type of the decorated property.

    Parameters

    • enumeration: Record<string, Value>

      The enum object to validate against.

    • Optionalopt: Partial<ValidatorOptions>

      Optional configuration.

    Returns DecoratorType<This, Value | Value[]>

    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
    }