I'm working on a function
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);
}
This function is specifically designed to work with either Bank or Owner types, and nothing else. These two types do not share any interface or inheritance chain.
My current implementation might not be the most elegant solution for this scenario. Is there a better way to achieve something like
uniqueIds<T> where T Bank | Owner
without having to stick with my current approach?