Omit on Union type
type Union =
| {
a: "a";
user?: string;
}
| {
b: "b";
user?: string;
};
type X = Omit<Union, "user">; // X is {}
Using DistributiveOmit
:
type DistributiveOmit<T, TOmitted extends PropertyKey> = T extends any
? Omit<T, TOmitted>
: never;
type Union =
| {
a: "a";
user?: string;
}
| {
b: "b";
user?: string;
};
type X = DistributiveOmit<Union, "user">;
/*
Omit<{
a: "a";
user?: string | undefined;
}, "user"> | Omit<{
b: "b";
user?: string | undefined;
}, "user">
*/
标签:DistributiveOmit,Typescript,string,Union,Omit,user,type From: https://www.cnblogs.com/Answer1215/p/17674089.html