The element type of the result.
The readonly tuple whose shape to keep.
type M1 = Tuple.MapTo<boolean, [1, 'a']>; // readonly [boolean, boolean]
type M2 = Tuple.MapTo<string, readonly number[]>; // readonly string[]
type M3 = Tuple.MapTo<string, readonly []>; // readonly []
type M4 = Tuple.MapTo<string, readonly [1, 2?]>; // readonly [string, (string | undefined)?]
type M5 = Tuple.MapTo<string, readonly [1, ...(readonly 2[])]>; // readonly [string, ...(readonly string[])]
// The usual reason to reach for it: naming the shape of a mapped result inside
// a function that is itself generic over the tuple.
declare const wrapAll: <T extends readonly unknown[]>(
values: T,
) => Tuple.MapTo<T[number] | undefined, T>;
Replaces every element of
TwithE, keeping its shape — length, rest and optional positions alike. The named spelling ofReadonly<{ [K in keyof T]: E }>.The counterpart of
ArrayElement, which reads the element type out; this one writes it back in.ReadonlyRecord<keyof T, E>is not a substitute: it keeps the keys but loses the fact that the result is an array at all, so nothing downstream can index, spread or destructure it as a tuple.Prefer
ChangeArrayElementwhenTmay carry a length-constraint brand (MinLengthArrayand friends): such a type is an intersection of a tuple and a brand object, which TypeScript does not treat as an array type, so the mapping below would maplength, every array method and the brand keys along with the elements, and yield a non-array object.Conversely, prefer this one when
Tis a generic type parameter:ChangeArrayElementanswers with a conditional onHasLengthConstraint<T>that a bareTcannot decide, so the deferred result is not assignable to the caller's own{ [K in keyof T]: E }. This mapping is, which is what makes it usable as an annotation inside a function that is itself generic over the tuple.