The minimum number of elements (inclusive). Must be a non-negative integer literal.
The maximum number of elements (inclusive). Must be a non-negative integer literal.
The type of elements in the array (defaults to unknown).
const selection = [1, 2, 3] as unknown as BoundedLengthArray<1, 5, number>;
const relaxed: BoundedLengthArray<0, 100, number> = selection; // OK ([1, 5] ⊆ [0, 100])
const atLeast1: MinLengthArray<1, number> = selection; // OK
const atMost5: MaxLengthArray<5, number> = selection; // OK
// const strict: BoundedLengthArray<2, 5, number> = selection; // Error! (1 < 2)
Branded readonly array type for arrays whose length is between
MinLengthandMaxLengthelements (both inclusive). Defined as the intersection of MinLengthArray and MaxLengthArray, so both bounds can be weakened independently:BoundedLengthArray<M1, M2, Elm>is assignable toBoundedLengthArray<N1, N2, Elm>ifM1 >= N1andM2 <= N2.This is the brand-based, lightweight counterpart of the structural tuple-based
BoundedLengthTuple; see MaxLengthArray for why it is much cheaper to type-check when the element type is large.