remix-validated-form icon indicating copy to clipboard operation
remix-validated-form copied to clipboard

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

Open qw-in opened this issue 2 years ago • 3 comments

Which packages are impacted?

  • [ ] remix-validated-form
  • [ ] @remix-validated-form/with-zod
  • [ ] @remix-validated-form/with-yup
  • [X] zod-form-data

What version of these packages are you using?

  • "zod": "^3.20.6",
  • "zod-form-data": "^2.0.0"

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

qw-in avatar Mar 04 '23 00:03 qw-in

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

airjp73 avatar Mar 04 '23 18:03 airjp73

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

qw-in avatar Mar 06 '23 00:03 qw-in

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 👍

matt-kinton avatar Mar 08 '23 19:03 matt-kinton

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. :(

airjp73 avatar Aug 08 '24 20:08 airjp73