1

I want to build a type that can fin all possible ways to traverse a Tree(object)

for example:

interface Tree = {
   a: { b: string, c: boolean },
   d: number
}

I want to have a type NestedObjectKeys that returns

NestedObjectKeys<Tree> ==> [ ['a', 'c'], ['a', 'b'], ['d'] ]

I tried my best, it's difficult for me as a ts beginner

Ken White
  • 123,280
  • 14
  • 225
  • 444
mod7ex
  • 874
  • 9
  • 27
  • 1
    Didn't understand the logic behind the example? – niceman Aug 21 '22 at 17:51
  • 1
    Are you perhaps referring to [combinatorics](https://en.wikipedia.org/wiki/Combinatorics), maybe more specifically [permutations](https://en.wikipedia.org/wiki/Permutation)? – jsejcksn Aug 21 '22 at 17:59
  • 1
    You are looking for *paths* through the tree, and the linked question's "pre-TS4.1 answer" should do what you want, using the `Leaves` type. – jcalz Aug 21 '22 at 19:30

0 Answers0