type Foo = {
a: string;
b: number;
};
type Bar = {
a: string;
c: boolean;
};
type Diff<T,Y> = {
[K in (keyof T | keyof Y) as K extends (keyof T & keyof Y) ?never:K]:K extends keyof T ? T[K]:K extends keyof Y ? Y[K]:never
}
type Result1 = Diff<Foo, Bar>; // { b: number, c: boolean }
type Result2 = Diff<Bar, Foo>; // { b: number, c: boolean }
typescript-剔除两个类型的公共属性
最新推荐文章于 2024-09-01 15:30:33 发布