This is an explanation for https://mobile.twitter.com/devanshj__/status/1204338726471688192
Okay so our task is to convert { a: A, b: B } | { b: B, c: C }
to { a: A, b: B, c?: never } | { a?: never b: B, c: C }
.
Now first thing to get is we somehow need each type from that union. We can use the distributive property of the conditional type. (I learned this from @jcalz) like this:
type Exact<Spec> = Spec extends any ? {
each: Spec // here Spec will be each union at a time
} : never;