My question is similar to Types from both keys and values of object in Typescript, but with an additional layer of nesting:
interface Outer {
a: {
b: number
},
c: {
d: string
}
}
And I'm only looking to retrieve the union type of all values, here number | string
.
Here's my stab:
type Values<T extends Record<string, any>> = T[keyof T]; // From previous SO answer
type InnerValues<
T extends Record<string, Record<string, any>>,
K extends keyof T
> = T[K][keyof T[K]];
type All = Values<Outer>;
type In = InnerValues<Outer, keyof Outer>; // expected number|string
but I have an error saying Outer
doesn't have an index type.