The index to update. A single literal names one position
exactly; a union of literals, or number, widens every candidate position
instead. An index beyond the end of T leaves it unchanged.
The new type for the element at index I.
The readonly tuple type.
type SA1 = Tuple.SetAt<1, 'x', [1, 2, 3]>; // readonly [1, 'x', 3]
type SA2 = Tuple.SetAt<0 | 2, 'x', [1, 2, 3]>; // readonly [1 | 'x', 2, 3 | 'x']
type SA3 = Tuple.SetAt<number, 'x', [1, 2, 3]>; // readonly [1 | 'x', 2 | 'x', 3 | 'x']
type SA4 = Tuple.SetAt<2, 'x', [1, 2]>; // readonly [1, 2] (index out of bounds: unchanged)
Creates a new readonly tuple type where the element at index
IinTis replaced with typeV.When
Iis a single numeric literal it names one position, and only that position changes. WhenIis a union — ornumber, which names no position in particular — the call replaces one of the candidate positions and never all of them, so each candidate is widened toT[I] | Vrather than set toVoutright.