logaretm / vee-validate

✅ Painless Vue forms
https://vee-validate.logaretm.com/v4
MIT License
10.79k stars 1.26k forks source link

zod catch casts to 'unknown' in toTypedSchema #4689

Closed andredewaard closed 7 months ago

andredewaard commented 7 months ago

What happened?

Whenever i create a zod object with unions that could be a string or number and transform those into a number the 'toTypedSchema' function returns 'unknown'

Reproduction steps

export const ClientsRequest = z.object({
  name: z.string().catch(''),
})

export type ClientsRequest = z.infer<typeof ClientsRequest>

const formSchema = toTypedSchema(ClientsRequest)
const { values } = useForm({
  validationSchema: formSchema,
})

values.name // unknown

Version

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

What browsers are you seeing the problem on?

Relevant log output

No response

Demo link

https://codesandbox.io/p/sandbox/veevalidate-qgf5tt?file=%2Fsrc%2Findex.ts%3A11%2C3

Code of Conduct

logaretm commented 7 months ago

Can you double check the sandbox link? Also this seems intended by Zod at the moment, I don't think it is a bug with vee-validate:

const rules = z.string().min(1, REQUIRED_MSG).min(8, MIN_MSG).catch('');
type type = input<typeof rules>;

// type: unknown