Skip to content

toTypedSchema fails to infer string from ZodEffects<ZodString, string, unknown> #5071

@sschneider-ihre-pvs

Description

@sschneider-ihre-pvs

What happened?

When using z.preprocess(..., z.string()) in a Zod schema, the result is a ZodEffects<ZodString, string, unknown>. This is expected and correct behavior from Zod.

However, when this schema is passed into toTypedSchema() from @vee-validate/zod and used with useForm(), the field's value is incorrectly inferred as unknown, rather than the actual inner type (string in this case).

This breaks downstream usage with defineField()which then expose Ref instead of Ref, despite the Zod schema clearly specifying a string via transformation.

Reproduction steps

...

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

Demo link

https://play.vuejs.org/#eNp9k8+O2jAQxl9llEsSaRtUtacsof/ESu2hrZY9te4hJBMwJJ7IdoAF8QZ9hb5cn6RjG1hWqvYSJfN94/n5s3OIPvR9thkwyqOxqbTsLRi0Qw9tqRaFiKwR0UQo2fWkLRxgMHhHuoMjNJo6iDeIrzZlK+vSYnx7ZdxfLHuqnymWHh57rGfVErvy4np/vdLo1CPUaAQ/qAYTzFtpl9Br7DVVaIxUC6EqUoahg6GAfUbzFVY2OQgF0D3eSWzrnMtPbYlTABKelkIxgcQyDzXA31AUBcTGal46hne+lEMcpzehZ58FLUmzTqrkderKTjymHveMc4AaG6nQT+c9FufgAtZpn5JUSCF/HkoSdnO1Lsfg9Fk4Iaka1CaHe2zGg1or2qrJDcwHjmFJAw+co9cCKx9fgPrJYwf8xTBXcEl8yii+TJrueg6QO8EupWE02JJe50L5/iw8eekuSW+B/X///Iap1qQ5KVeOoSY0oMgC7iQPJgUuYohPsLFQ41G4bQwnVHTD94wZG7nIVoYUX0Yfk4gq6nrZov7Wu7D4LubgFaeVbUvbL75m9YCnE+KeJVbr/9RXZudqIvqu0aDeoIgumi31Am2Qp7OvuOP3i9hRPbTsfkG8R0Pt4BiD7eOgasa+8nnaz/4f4GQfzHRnUZnzphyocx69X0T8R356YetPuG+yt76Pb0p0/Ae+lUqb

Code of Conduct

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