interface item {
a: string
c?: Array<item>
}
function g<const T extends item>(p: Array<T>) {
return {} as {[K in T as K['a']]: any}
}
// type of r is {a0: any, a1: any}
const r1 = g1([
{
a: 'a0',
c: [
{
a: 'ac0'
}
]
},
{
a: 'a1'
}
])
We can make the type that consisted with each specific property of array. But actually I want all a
property that in last depth, not only depth 1 of a
.
interface item {
a: string
c?: Array<item>
}
function g1<T>(g1:T) {
return {} // as ..?
}
// I hope that type of r1 is {a0: any, ac0: any, a1: any}
const r1 = g1([
{
a: 'a0',
c: [
{
a: 'ac0'
}
]
},
{
a: 'a1'
}
])
I want make the union key type with all a
properties of all last child.
Is it possible in TypeScript?
If it is possible, how?