My query has similarities to Types from both keys and values of object in Typescript, however, I am adding another level of nesting:
interface Outer {
a: {
b: number
},
c: {
d: string
}
}
I am specifically interested in obtaining the union type of all values, which in this case is number | string
.
This is what I have come up with so far:
type Values<T extends Record<string, any>> = T[keyof T]; // Extracting value types
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
However, I encountered an error stating that Outer
does not have an index type.