zod icon indicating copy to clipboard operation
zod copied to clipboard

Recursive type with promise - Recursive property returns a unresolved promise

Open tsteckenborn opened this issue 2 years ago • 0 comments

Hello all,

I just came across a case that confuses me.

The APIs response has a recursive structure. The object returned from the function call to the API is a promise.

I'm somewhat following the docs having an interface and then calling

[...]z.ZodType<Something> =
	z.lazy(() =>
		z.promise(
			z.object({[...]

The non-recursive attributes are resolved, but the attributes of the recursive property are now a promise (even though they are contained in the object I get back). Somehow I seem to be missing how I should explain that the outer object is a promise, not every recursive element in it.

Would appreciate it if someone could jump in with an explanation 👍

tsteckenborn avatar Oct 27 '22 16:10 tsteckenborn