robertLichtnow / zod-formik-adapter

An adapter for zod object validation to Formik validation schema
https://www.npmjs.com/package/zod-formik-adapter
MIT License
159 stars 15 forks source link

[BUG] schema with transform has type mismatch #20

Open bastibuck opened 1 year ago

bastibuck commented 1 year ago

Describe the bug When describing a schema that has one or more transform()s. Right now a type error is shown when using validationSchema: toFormikValidationSchema(mySchema),.

To Reproduce Steps to reproduce the behavior:

  1. Create a schema containing transform e.g. string => number
  2. Use toFormikValidationSchema with that schema
  3. See error
The types of '_input.age' are incompatible between these types.
    Type 'string' is not assignable to type 'number'.

Expected behavior The TypeError should not be shown as only the fully transformed type should be considered.

Node version: 19.12.0

Zod, Formik and zod-formik-adapter versions:

Additional context Check this CodeSandbox for example https://codesandbox.io/s/formik-zod-test-forked-eyoy4j?file=/index.tsx