Type safety with <Field /> as
prop
#3268
Replies: 1 comment
-
You can see some experiments with this over here The field component is very complex, so it's not easy or maybe even possible to get every type working with Typescript just yet. It's getting there, though. |
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 love the simplicity of utilizing the
<Field />
component as well as itsas
prop as a means of rendering my own input component that, in addition to standard input props, has an additional custom prop.However, with Typescript, it seems the
<Field />
component doesn't make available theas
component's props to the<Field />
component so that I can ensure that the props being added are type-safe with my custom component.Example (with irrelevant code removed for brevity):
Like in the example above, how can I ensure that the value I'm providing to
isInvalid
is type-safe? In addition, how can I ensure that the bogus prop I added,anInvalidProp
, results in an error?My initial thought was that
<Field />
could accept a type argument, such as<Field<MyCustomInputProps> />
but the interface does not allow for that. I also tried thecomponent
prop but that also does not have the type inference/safety.The long, painful way of doing this to get the type safety is to not use
<Field />
and instead manually add the relevant field props but I was hoping to avoid that.Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions