ts-type-forge
    Preparing search index...

    Type Alias TakeLast<N, T>

    TakeLast: TSTypeForgeInternals_PinsOneNumber<N> extends true
        ? TakeLastImpl<N, T, readonly []>
        : readonly T[number][]

    Takes the last N elements from a readonly tuple T.

    Type Parameters

    • N extends number

      The number of elements to take. Only a single numeric literal pins a length; a union of literals and number alike answer an unsized array, which every possible result satisfies.

    • T extends readonly unknown[]

      The readonly tuple type.

    A new readonly tuple type containing the last N elements. If N is larger than the length of T, returns T.

    type TL1 = Tuple.TakeLast<2, [1, 2, 3]>; // readonly [2, 3]
    type TL2 = Tuple.TakeLast<5, [1, 2, 3]>; // readonly [1, 2, 3]
    type TL3 = Tuple.TakeLast<0, [1, 2, 3]>; // readonly []
    type TL4 = Tuple.TakeLast<1 | 2, [1, 2, 3]>; // readonly (1 | 2 | 3)[]
    type TL5 = Tuple.TakeLast<number, [1, 2, 3]>; // readonly (1 | 2 | 3)[]