-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remix singleFetch and FieldError type #100
Comments
running into this as well! |
I'll try to fix this asap, hopefully very soon |
@luzat what version of Remix is this on? Is it prior to 2.11.x? I don't get the same errors in the latest version, or I'm missing something? |
@AlemTuzlak This was with Remix 2.10.0 I think (current package versions from bug report date), but I can still reproduce it with Remix 2.11.2 and current versions of remix-hook-form and react-hook-form. Here's a more minimal test: import { zodResolver } from '@hookform/resolvers/zod'
import { unstable_defineAction as defineAction } from '@remix-run/node'
import { getValidatedFormData } from 'remix-hook-form'
import { z } from 'zod'
const schema = z.object({
value: z.string(),
})
type FormData = Zod.infer<typeof schema>
const resolver = zodResolver(schema)
export const action = defineAction(async ({ request }) => {
const { errors } = await getValidatedFormData<FormData>(request, resolver)
return errors ? { errors } : {}
}) TypeScript error:
With
Package versions are 2.11.2 for Remix, 5.0.4 for remix-hook-form, 7.53.0 for react-hook-form and 5.5.4 for TypeScript. This is to be expected, given the |
@luzat ahh okay the defineAction was the thing that was missing for me, FYI this API is completely removed in Remix on this PR: |
@AlemTuzlak Looking at this, it's certainly not that important to fix the types currently. If the types are to be improved in the future, it might make more sense to first include an option or helper in react-hook-form, to (optionally) return Ref-free types. |
I'm just a bit hesitant to add a fix for this now as there is a lot of API churn around single_fetch and there is no guarantee that this will be the case. I definitely plan to do something about it if it doesn't go away, until then your workaround will work for anyone on the unstable feature. |
@luzat sorry to do this again, but I saw the latest release of remix fixed some type issues with single fetch, could you check if this is still an issue? |
I have set up my Remix project to use
unstable_singleFetch
. This means that I am generally not usingreturn json({ … })
(even though I sometimes could):This gives a TypeScript error, because
FieldError
elements contains aref?: Ref
which cannot be serialized.I think
ref
will always be undefined here, though, andgetValidatedFormData
's return type should probably reflect that. This may need to be solved for other non-hook methods, too. As a hack, I did this:I am not sure if this solves every problem with
singleFetch
, but the cast avoids TypeScript errors. I will probably wrap all relevant methods for now, but it might suffice to defineFieldErrorsNoRef
(and the other relevant types) as above and change the cast invalidateFormData
:This is obviously not very elegant as it mirrors the types from
react-hook-form
.The text was updated successfully, but these errors were encountered: