You can capture the parameters in a tuple type using a generic type parameter with a constraint of any[]
for a rest parameter. You can the use UnionToIntersection
described here to merge all tuple item types into a single intersection type
type UnionToIntersection<U> =
(U extends any ? (k: U)=>void : never) extends ((k: infer I)=>void) ? I : never
function tuple<T extends any[]>(...t: T) {
let newob = {} as UnionToIntersection<T[number]>;
for (let ob of t) {
Object.assign(newob, ob);
}
return newob;
}
CLICK HERE to find out more related problems solutions.