I have a recursively typed object that I want to retrieve the keys and any child keys of a specific type from.
For example, I am looking to extract a union type consisting of:
'/another' | '/parent' | '/child'
Here is an illustration:
export interface RouteEntry {
readonly name: string,
readonly nested : RouteList | null
}
export interface RouteList {
readonly [key : string] : RouteEntry
}
export const list : RouteList = {
'/parent': {
name: 'parentTitle',
nested: {
'/child': {
name: 'child',
nested: null,
},
},
},
'/another': {
name: 'anotherTitle',
nested: null
},
}
In TypeScript, you can use keyof typeof RouteList to obtain the union type:
'/another' | '/parent'
Is there a way to also capture the nested types?