zod icon indicating copy to clipboard operation
zod copied to clipboard

v4: `parse` and `safeParse` no longer accept `path` in params

Open arg0NNY opened this issue 8 months ago • 1 comments

This was helpful when validating some specific deeply-nested properties inside an object without worrying about manually altering the path in the root and union issues for it to be a valid path relative to the root object and just simply handling issues as-is.

Here's the ParseParams interface in v3 used by parse and safeParse: https://github.com/colinhacks/zod/blob/8cca93b7cc3f8c5fa17303bbb82d5c531ec24f33/src/helpers/parseUtil.ts#L43-L47

I couldn't find any mentions of this change in the migration guide so I assume it was unintentional.

arg0NNY avatar Apr 12 '25 12:04 arg0NNY

Also, path is no longer available inside transforms and refinements' ctx, which was crucial for recursive types to make validations based on the current path. Notify me if I should create a separate issue for this.

arg0NNY avatar Apr 13 '25 23:04 arg0NNY

I'm afraid these are both intentional and known changes in Zod 4.

The top-level path param in the parse methods was just a mistake. That was intended as an internal field.

As for ctx.path, I've added the following to the changelog:

Image

Your use case with recursive types is interesting, but the ctx.path information just isn't available anymore with Zod's new parsing architecture. Path arrays are constructed lazily only after a validation error is encountered.

colinhacks avatar May 15 '25 07:05 colinhacks