I have the following object:
<code>const object = {
label: 'A',
value: 'a',
children: [
{
label: 'B',
value: 'b',
children: [
{
label: 'C',
value: 'c',
},
{
label: 'D',
value: 'd',
},
],
},
{
label: 'E',
value: 'e',
children: [
{
label: 'F',
value: 'f',
},
{
label: 'G',
value: 'g',
},
],
},
],
} as const;
</code>
<code>const object = {
label: 'A',
value: 'a',
children: [
{
label: 'B',
value: 'b',
children: [
{
label: 'C',
value: 'c',
},
{
label: 'D',
value: 'd',
},
],
},
{
label: 'E',
value: 'e',
children: [
{
label: 'F',
value: 'f',
},
{
label: 'G',
value: 'g',
},
],
},
],
} as const;
</code>
const object = {
label: 'A',
value: 'a',
children: [
{
label: 'B',
value: 'b',
children: [
{
label: 'C',
value: 'c',
},
{
label: 'D',
value: 'd',
},
],
},
{
label: 'E',
value: 'e',
children: [
{
label: 'F',
value: 'f',
},
{
label: 'G',
value: 'g',
},
],
},
],
} as const;
From this object, I want to derive the following type:
<code>{
a: {
b: {
c: boolean,
d: boolean,
},
e: {
f: boolean,
g: boolean,
},
}
}
</code>
<code>{
a: {
b: {
c: boolean,
d: boolean,
},
e: {
f: boolean,
g: boolean,
},
}
}
</code>
{
a: {
b: {
c: boolean,
d: boolean,
},
e: {
f: boolean,
g: boolean,
},
}
}
However, it seems that recursion in TypeScript is limited. I have tried many different approaches but cannot figure out how to achieve this.
How can I recursively generate a type from this nested structure?
New contributor
RandomDude1234 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.