【发布时间】:2018-08-04 03:51:18
【问题描述】:
我有一个函数
uniqueIds(first: any[], second: any[]): number[] {
let prop = first[0] instanceof Owner ? "OwnerId"
: "BankId";
return _.unique(
_.map(
first,
o => o[prop]
)
.concat(
_.map(
second,
o => o[prop]
)
)
).filter(o => o);
}
银行或所有者是我希望此函数采用的可能类型,仅此而已。银行和所有者不共享接口或继承链
根据传入的类型,我想根据函数内第一行中看到的属性对对象进行索引。
我的东西看起来很丑,有没有办法
uniqueIds<T> where T Bank | Owner 类似的东西而不诉诸于
我现在在做什么?
【问题讨论】:
标签: typescript typescript-generics