Replies: 1 comment
-
Did you find a solution for this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am designing reusable controls that encapsulate react-hook-forms controlled controls.
For example, let's say I am designing a SupplierDropdown to edit a certain property in a FieldValues object...
I want to be able to use it like so:
<SupplierDropdown<MyFieldValues> name="Supplier" />
The name property is passed to a react hook forms Controller as the name property of the Controller object. High level the reusable control SupplierDropdown is declared like this:
But I would also want to constraint that the path TName points to needs to be of type SupplierDTO. Or in react hook form that FieldPathValue<TFieldValues, TName> is equal SupplierDTO. For example if TFieldValues is passed the type:
I want to make sure with a typescript type constraint that the property that TName points to (in this case "Supplier") is of type SupplierDTO.
How could I do that given the fact that FieldPath can be a single string, but it can also be a hierarchical path like "Document.Invoice.Supplier".
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions