• @MapTo decorator map each value of an array to a child relation constructor. This is useful when a property is an array, and you want each item in the array to be processed by a specific relation.

    Type Parameters

    • This extends object

      The type of the class the decorator is applied to.

    • Value

      The type of the decorated property.

    • Args extends string

    Parameters

    Returns DecoratorType<This, Value>

    The property decorator function.

    In the following example, the @MapTo decorator passes each element of the array passed as an argument to the child 'Relation' (SubProtocol) constructor. The SubProtocol then uses this value to set the length of array of number in the data property.

    class SubProtocol {
    _size: number

    @Count('_size')
    @Relation(PrimitiveSymbol.u8)
    data: number[]

    constructor(size: number) {
    this._size = size
    }
    }

    class Protocol {
    @MapTo([1, 2])
    @Relation(SubProtocol)
    field: SubProtocol[]
    }