type NestedObject = {
amount: number,
error: string | null,
data: {
rows: [],
messages: {
goodNews: string | null,
badNews: string | null
}
}
}
//attempting to recursively retrieve all keys
type AllKeys<T, K extends keyof T> =
T extends object ?
T extends infer O ?
{keys: K | AllKeys<O, keyof O> : never
: K
type Test = AllKeys<NestedObject, keyof NestedObject>
as a result I got:
type Test = { keys: 'amount' | 'error' | 'data' | ... }
however, I aim to obtain:
type Test = { keys: 'amount' | 'error' | 'data' | 'rows' | 'messages' | 'goodNews' | 'badNews'}