devtypes - v2.0.0
    Preparing search index...

    Type Alias TupleTake<T, N, R>

    TupleTake: R["length"] extends N
        ? R
        : T extends readonly [infer H, ...(infer Rest)]
            ? TupleTake<Rest, N, readonly [...R, H]>
            : R

    Take the first N elements of a tuple.

    Type Parameters

    • T extends readonly any[]

      Tuple type

    • N extends number

      Number of elements to take

    • R extends readonly any[] = []

    Produces a new tuple containing the first N elements from the input tuple. If N exceeds the tuple length, returns the entire tuple.

    type T = TupleTake< [ 1, 2, 3, 4 ], 2 >;  // [ 1, 2 ]