I'm picking up TS again and I can't believe this is so hard to do. I must be missing something obvious
const foo = {a: {b: 1}, u: {v: 2}} as const;
const f = (x: 'a'|'u', y: 'b'|'v') => {
const foo_u = foo[x];
if(v in foo_u) {
const foo_u_v = foo_u[y]
}
}
I get the error
Property 'b' does not exist on type '{ readonly b: 1; } | { readonly v: 2; }'
I understand that keyof '{ readonly b: 1; } | { readonly v: 2; }' is never, but this code cannot fail at runtime.
What is the least annoying way to deal with that?