#How to derive a concatenated string union from a tree like structure

2 messages · Page 1 of 1 (latest)

frail oriole
#

I have the following interface which represents a tree like structure

interface IRoute {
  readonly path: string,
  readonly children?: IRoute[]
}

Is it possible to derive a string union of all the possible paths?
eg

type AllRoutes = 'path1' | 'path1/path2' | `path3' | ...;
#

Heres a playground link of sample data and the type I'm automatically trying to derive