ts-type-forge
    Preparing search index...

    Type Alias SetAt<I, V, T>

    SetAt: IsFixedLengthList<T> extends true
        ? Tuple.SetAt<I, V, T>
        : readonly (T[number] | V)[]

    Creates a new array/tuple type where the element at index I in T is replaced with type V. If T is a tuple, it returns a new tuple type with the element at I updated. If T is a general array, it returns a general array type readonly (T[number] | V)[].

    Type Parameters

    • I extends number

      The index to update (must be a valid index for T if T is a tuple).

    • V

      The new type for the element at index I.

    • T extends readonly unknown[]

      The readonly array or tuple type.

    A new array/tuple type with the element at index I updated.

    type SA1 = List.SetAt<1, 'x', [1, 2, 3]>; // readonly [1, 'x', 3]
    type SA2 = List.SetAt<1, 'x', readonly number[]>; // readonly (string | number)[]
    // type SA3 = List.SetAt<2, 'x', [1, 2]>; // Error if I is out of bounds for tuple