-
Notifications
You must be signed in to change notification settings - Fork 251
Typescript support for React HTML element props #552
Comments
@sl33kr I am new to TypeScript (though I'm working on adding more strict TypeScript typings to RRF in future versions). Can you show me the code that doesn't work with the current typings? |
@davidkpiano I'm new to typescript as well. Here is an example of what I'm trying to do.
In typescript the className on Field is invalid as FieldProps doesn't extend HTMLProps. Same case for ControlProps. I'm not sure if there is a way to provide these props without either explicitly adding them to FieldProps or making it extend HTMLProps. I then tried to use the controlProps="{{className: "btn-group"}}" however this wasn't available on Field either. I ended up rendering the div manually.
|
cc. @tiagoefmoraes @zach-waggoner would any of you know how to remedy this? |
I did try to interface merge in our project to add the "extends HTMLProps" to FieldProps and ControlProps to work around the issue but I could get this working either. |
Ok I got the merge working. Messes with intellisense but at least it compiles.
|
As Field and Control pass the properties down it makes sense for them to extend HTMLProps. |
Typescript FieldProps extends ControlPropsextends HTMLProps. Fixes #552
Hi there,
We are using this library with typescript, and have found an issue trying to add styling to the div that the Field component renders.
The documentation says
In typescript this doesn't seem to be the case.
ControlProps
extendsFieldProps
. I would have thought for this to work either the relationship would have to be the other way around, there should be a common interface to both or they use the same interface.In my case I was able to move forward by modifying the react-redux-form.d.ts file and making
FieldProps
extend `React.HTMLProps. This meant I was then able to pass down the standard props as I could do with normal javascript to both Field and Control. I do however see how this may not be correct or desirable.How should I be doing this? I can see that I could use the
component
property and render the div myself, bit is nice to have react-redux-form do it for me and just pass down myclassName
prop.The text was updated successfully, but these errors were encountered: