Skip to content

Vee validate zod schema defaultValue #5091

@shammahr

Description

@shammahr

What happened?

zod: 4.1.11
@vee-validate/zod: 4.15.1
vee-validate: 4.15.1

Expected behavior

Zod’s default function should be preserved and not shadowed by a string value when used through toTypedSchema.

value._def contains both a defaultValue getter and a plain string property of the same name, which shadows the getter. This makes value._def.defaultValue() fail inside @vee-validate/zod.

Reproduction steps

  1. Create the Zod schema above.
  2. Wrap it with toTypedSchema.
  3. Initialize useForm with it.
  4. Observe the runtime error during schema casting.

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

vee-validate-zod.mjs:158 Uncaught (in promise) TypeError: value._def.defaultValue is not a function
    at vee-validate-zod.mjs:158:37
    at Array.map (<anonymous>)
    at getDefaults (vee-validate-zod.mjs:156:60)
    at Object.cast (vee-validate-zod.mjs:94:34)
    at resolveInitialValues (vee-validate.mjs:2170:29)
    at useForm (vee-validate.mjs:2189:33)
    at setup (xxxx.vue:24:14)
    at callWithErrorHandling (runtime-core.esm-bundler.js:199:19)
    at setupStatefulComponent (runtime-core.esm-bundler.js:7996:25)
    at setupComponent (runtime-core.esm-bundler.js:7957:36)

Demo link

https://codesandbox.io/p/devbox/qm2pv6

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