Reproduction:
const recursiveSchema = z.object({
id: z.string(),
get children() {
return z.array(recursiveSchema);
},
});
console.log(zx.toType(recursiveSchema)); // RangeError: Maximum call stack size exceeded
Probably related to #540 as well.
One possible solution to this could be to require a recursive schema to have a description (exist in the z.globalRegistry) so that you can use the description string as a value to break the infinite loop.
The proposes solution would also be nice to have for schemas that are not recursive, but contain other schemas, so that you could list them separately (using their description as placeholder where they are used in other schemas) instead of inlining all types.
I could try to make a PR if you agree with the proposed solution.