#Union discriminated on object
4 messages · Page 1 of 1 (latest)
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}
...```
You can choose specific lines to embed by selecting them before copying the link.
Discriminated unions are a special case and that special case wasn't extended to nested properties