Skip to content

Upgrading from 4.3.6 to 4.4.x causes issues with preprocess + catch #5937

Description

@terrymun

I am using zod to parse payload we received from URLSearchParams, which requires transforming comma-separated string values into an array of string (which can potentially be empty/undefined). In v4.3.6 and below, the following schema works:

z.object({
  area: z.preprocess(v => v ? v.toString().split(',') : [], z.array(z.string())).catch([])
})

And the payload is as follow:

{}

v4.3.6 on Zod Playground, which works without any issue ✅

However, after upgrading to 4.4.x (4.4.0, 4.4.1, and 4.4.2), I get the following error:

invalid_type - Invalid input: expected nonoptional, received undefined

All these versions are showing the same error:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions