One diagnostic. Discriminated on code, so switch (d.code) narrows d.data to that code's
payload with no cast — which is the point of typing the payloads at all.
Written as a distributive conditional over the code union rather than as one object with a generic
data, which is what makes the narrowing work; the shape is spelled out inline so that no helper
type of its own leaks into the published API.
One diagnostic. Discriminated on
code, soswitch (d.code)narrowsd.datato that code's payload with no cast — which is the point of typing the payloads at all.Written as a distributive conditional over the code union rather than as one object with a generic
data, which is what makes the narrowing work; the shape is spelled out inline so that no helper type of its own leaks into the published API.