1

I am trying to convert some types. I have a "union" type of this kind

interface A {
    a: number;
    b: string;
}

interface B {
    b: number;
    c: string[];
}

type Orig = {
    $case: 'a';
    a: A;
} | {
    $case: 'b';
    b: B;
}

and I would like to convert it in a more "compact" form, basically removing the $case

type Goal = {
    a: A;
} | {
    b: B;
}

But I don't want to "write" the Goal type by hand, I would like to have it as a depended type, maybe using Record / Exclude / Omit etc.. but I had no luck :/

Here is the playground with also my tentatives

Vito De Tullio
  • 2,332
  • 3
  • 33
  • 52
  • You're looking for "distributive `Omit`", as shown [in this playground link](https://tsplay.dev/w6xMym) and in the answer to [the linked question](https://stackoverflow.com/questions/57103834/typescript-omit-a-property-from-all-interfaces-in-a-union-but-keep-the-union-s). – jcalz Mar 23 '23 at 13:48

0 Answers0