【发布时间】:2021-09-27 04:36:06
【问题描述】:
鉴于此输入:
export type Test = {
one: {
a: string;
b: string;
c: string;
};
two: {
a: string;
b: string;
d: string;
};
}
我需要像CombinedChildren<T> 这样的泛型,它输出以下类型:
export type Combined = {
a?: string;
b?: string;
c?: string;
d?: string;
}
基本上,它获取子属性并将它们组合起来,包括它们,即使它们并非存在于所有子元素中。
试过
export type KeyOfTest = Partial<Test[keyof Test]>
export type MappedKeyOfTest = Partial<{
[key in keyof Test[keyof Test]]: Test[keyof Test][key]
}>
但没有一个输出完全符合我的要求。
【问题讨论】:
标签: typescript generics