【发布时间】:2020-10-29 21:45:56
【问题描述】:
是否可以获取不同对象的元组,并获得所有这些对象组合的类型?例如,如果我有一个这样的元组:
const t = tuple({current: 1}, {old: 2}, {new: 3}); //this should be interpreted as [{current: number;}, {old: number;}, {new: number;}]
然后我将这些对象组合成一个对象:
let newob = {};
for(let ob of t) {
Object.assign(newob, ob);
}
我能不能让 typescript 把这个新对象当作一个
typeof t[0] & typeof t[1] & typeof t[2]
在这种情况下是
{current: number; old: number; new: number;}
无需手动输入所有内容?
我希望它适用于任何元组和元组内的任何对象
【问题讨论】:
标签: typescript