Consider the following:
type Properties = {
foo: { n: number };
bar: { s: string };
baz: { b: boolean };
};
declare function retrieveValues<K extends keyof Properties>(add?: K[]): Pick<Properties, K>[K];
// what happens
const x: { n: number } | { s: string } = retrieveValues(['foo', 'bar']);
// what I'm really trying to express (type error)
const y: { n: number } & { s: string } = retrieveValues(['foo', 'bar']);
Is there a way to get an intersection of the properties of Pick<Properties, K>
? Or just a different way to get the intersection of a set of types based on the presence of relevant strings in an array?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…