I have this function which merge arbitrary numbers of objects
function merge(...objs) {
return objs.reduce((res, cur) => {
for (const key in cur) {
res[key] = cur[key]
}
return res;
}, {});
}
at first I thought this function could not be type annotated, but then I tried rest parameter which is quite similar to my merge
function
const obj = {
...{ name: { ownName: 'Lewis' } },
...{ link: 'google.com' }
}
type Obj = typeof obj // I can happily get the Obj type
Then I came across this idea: when u don't know the types in advance, use generic. But how can I define rest generic types like
function merge<T, U, V...>(...objs: Array<T | U | V...>)