#Union discriminated on object

4 messages · Page 1 of 1 (latest)

velvet charm
#

Hi all, hopefully a quick one - does anyone know why using an object as a discriminated value does not cause the related types to narrow?

versed depotBOT
#
m.a.t.t.t#0

Preview:```ts
type Union =
| {disc: "a"; value: number}
| {disc: "b"; value: string}

function abc(u: Union) {
switch (u.disc) {
case "a": {
u.value
// ^?
}
}
}

type UnionObj =
| {disc: {i: "a"}; value: number}
| {disc: {i: "b"}; value: string}
...```

olive turtle
#

Discriminated unions are a special case and that special case wasn't extended to nested properties