type A = {
prop1: string
prop2: B
}
type B = {
prop3: string
prop4: boolean
}
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
type Flatten<T, K extends keyof T> = UnionToIntersection<T[K]> & Omit<T, K>;
type Both = Flatten<A,'prop2'>
const result: Both = {prop1: 'one', prop3: 'two', prop4: false}
编辑:这更简单:
type Flatten<T, K extends keyof T> = Omit<T, K> & T[K];
type Both = Flatten<A,'prop2'>
1条答案
按热度按时间xxhby3vn1#
您可以使用此类型:
编辑:这更简单: