After countless attempts, I finally managed to create a generic type that provides me with all possible combinations of JSON key lists and values. Additionally, I have developed a method to limit the recursion within this type.
type EditAction<T,P extends keyof T,Prev extends any[]> = {
data : T[P]
id : [...Prev, P]
prev : Prev
}
type EditActions<T, Depth extends number = 50, Prev extends any[] = []> = {
[P in keyof T] : T[P] extends JsonType
? (Prev["length"] extends Depth
? EditAction<T,P,Prev>
: (EditAction<T,P,Prev> | EditActions<T[P],Depth,[...Prev,P]>))
: EditAction<T,P,Prev>
}[keyof T]
Despite implementing a depth limitation, TypeScript throws an error if the depth exceeds 9, leaving me puzzled. It appears that TypeScript's maximum recursion is capped at 50, leading to the following error message:
Type instantiation is excessively deep and possibly infinite.ts(2589)
(property) payload: EditActions<T, 50, []>