ts-type-forge
    Preparing search index...

    Type Alias SetAt<T, I, V>

    SetAt: IsFixedLengthList<T> extends true
        ? Tuple.SetAt<T, I, V>
        : 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

    • T extends readonly unknown[]

      The readonly array or tuple type.

    • 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.

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

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