Edit:
Please read the issues mentioned by @jcalz in the comment to make sure you have understand implications of the workaround down under.
If you implement your own custom recursive types, it is also a good idea to safely limit the recursion depth with an iteration counter, like @Maciej Sikora proposed (especially if you publish a public library).
Workaround
With recursive types, this error sometimes cannot be avoided. Fortunately, there is a workaround:
type Paths<Obj> = Obj extends object
? {
[Key in keyof Obj]: Obj[Key] extends infer I ? Prepend<Paths<I>, Key> : never
// add this ^ ^
}[keyof Obj]
: [];
Above infer declaration will defer type evaluation, so the hard instantiation limit counter is not hit. In consequence that will prevent the Type instantiation is excessively deep compile error. Be sure to test the type thoroughly, as you have disabled a compiler safety check with the escape-hatch.
Alternatively, you can optimize Paths type yourself or use a library like ts-toolbelt, that already has one (the author @pirix-gh discovered above trick and uses this mechanism in his library).
Further links