airjp73 / rvf

Easy form validation and state management for React and Remix
https://rvf-js.io
MIT License
827 stars 66 forks source link

[Bug]: zfd `.error.flatten()` no longer matches `z.inferFlattenedErrors<typeof schema>` #250

Closed qw-in closed 1 month ago

qw-in commented 1 year ago

Which packages are impacted?

What version of these packages are you using?

Please provide a link to a minimal reproduction of the issue.

https://codesandbox.io/s/silly-raman-8dsex1?file=/src/index.tsx

Steps to Reproduce the Bug or Issue

Note the type error on line 13:

Type 'typeToFlattenedError<FormDataLikeInput, string>' is not assignable to type 'ValidationErrors'.
  Types of property 'fieldErrors' are incompatible.
    Type '{ [iterator]?: string[] | undefined; entries?: string[] | undefined; }' has no properties in common with type '{ field?: string[] | undefined; }'.ts(2322)

Expected behavior

Was hoping to keep using z.inferFlattenedErrors but LMK if there is an alternative I should use

Screenshots or Videos

No response

Platform

N/A

Additional context

No response

airjp73 commented 1 year ago

Looks like this issue occurs any time the output shape has been altered via a transform. This issue should probably be raised with zod itself as well.

Here's a reproduction without zod-form-data: Typescript playground link

qw-in commented 1 year ago

@airjp73 thanks for having a look, I'll open an upstream issue with your repro

matt-kinton commented 1 year ago

I've reverted to v1.3.1 which has fixed the problem for me instead of doing a type assertion on the resulting error. Looking forward to seeing this fixed 👍

airjp73 commented 1 month ago

In the upstream issue, Colin said that this doesn't seem like a solvable issue. So, unfortunately, I'm going to close this issue for now until they have a resolution. :(