Type Challenge: Generic Form Field Component with Type-Safe Path Selection #12461
Unanswered
alexwork1611
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm trying to create a reusable form field component that:
T
UseFormReturn<TFormValues>
instancefieldName
that should only allow paths (usingFieldPath
) where the corresponding value type (usingFieldPathValue
) matchesT
Example usage:
Is there a way to achieve this type safety using RHF's type system? I've tried various approaches with
FieldPath
andFieldPathValue
but haven't found a clean solution.Here's what I've tried:
Hope it's not too confusing lol.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions