ts-type-forge
    Preparing search index...

    Type Alias MutableBoundedLengthArray<MinLength, MaxLength, Elm>

    MutableBoundedLengthArray: MutableMaxLengthArray<MaxLength, Elm> & MutableMinLengthArray<
        MinLength,
        Elm,
    >

    Mutable counterpart of BoundedLengthArray: a branded mutable array type for arrays whose length is between MinLength and MaxLength elements (both inclusive). Defined as the intersection of MutableMinLengthArray and MutableMaxLengthArray, so the clamped structural prefix stays mutable and both bounds can be weakened independently. The brand is the same as BoundedLengthArray, so a MutableBoundedLengthArray<M1, M2, Elm> is assignable to BoundedLengthArray<M1, M2, Elm>.

    Type Parameters

    • MinLength extends SupportedLength

      The minimum number of elements (inclusive). Must be a non-negative integer literal.

    • MaxLength extends SupportedLength

      The maximum number of elements (inclusive). Must be a non-negative integer literal.

    • Elm = unknown

      The type of elements in the array (defaults to unknown).

    const selection = [1, 2, 3] as unknown as MutableBoundedLengthArray<
    1,
    5,
    number
    >;

    selection[0] = 10; // OK — elements are mutable
    const relaxed: BoundedLengthArray<0, 100, number> = selection; // OK ([1, 5] ⊆ [0, 100])
    // const strict: MutableBoundedLengthArray<2, 5, number> = selection; // Error! (1 < 2)