Let's imagine I have a unique set of individuals:
const group = {
Alex: ['Ben', 'Chris'],
Sarah: ['Dylan'],
} as const;
With the help of constant clarifications, I can define the specific types like so:
type Parent = keyof typeof group; // Alex|Sarah
type Child = typeof group[Parent][number]; // Ben|Chris|Dylan
Now consider this different set, with another layer added:
const offspring = {
Alex: {
Ben: ['Ella', 'Fiona'],
Chris: ['Hannah'],
},
Sarah: {
Dylan: ['Isabella'],
},
} as const;
We can identify the initial level with:
type Ancestor = keyof typeof offspring; // Alex|Sarah
But how do we pinpoint the exact names for Parent
(Alex, Sarah) and Child
(Ella, Fiona, Hannah, Isabella)?