type IfUnbounded = number extends T['length'] ? THEN : ELSE; type AddUntil = T['length'] extends L ? T : AddUntil; /** * Last => type of last element in tuple T */ export type Last = [...T] extends [...rest: any[], last: infer R] ? R : IfUnbounded /** * AllExceptLast => Type of tuple that matches T except it drops the last element */ export type AllExceptLast = [...T] extends [...rest: infer R, last: any] ? R : IfUnbounded; /** * Repeat => tuple of length L where each member is of type T */ export type Repeat = number extends L ? T[] : AddUntil;