I have a type object of nodes, many of which specify other nodes as children. For example:
type Nodes = {
a: {
children: ["b"]
},
b: {
children: ["c"]
},
c: {
children: []
}
}
I'm trying to create a generic type, something like type DescendantName<T extends keyof Nodes> = ... that produces a union of the descendant names of Nodes[T], such that DescendantName<"a"> produces "b" | "c".
I tried a straightforward recursive syntax but got a circularity type error:
type DescendantName<T extends keyof Nodes> = Nodes[T]["children"][number] | DescendantName<Nodes[T]["children"][number]>
// Type alias 'DescendantName' circularly references itself. ts(2456)
Can anyone tell me how to make a working generic type like this?