Type error when using custom HtmlInput component.
See original GitHub issueWhat is the current behavior?
TypeScript error in /home/dema/tmp/rff-bug/src/App.tsx(36,23):
Type 'FunctionComponent<InputProps>' is not assignable to type '"input" | "select" | "textarea" | ComponentClass<FieldRenderProps<any, HTMLElement>, any> | FunctionComponent<FieldRenderProps<any, HTMLElement>> | undefined'.
Type 'FunctionComponent<InputProps>' is not assignable to type 'FunctionComponent<FieldRenderProps<any, HTMLElement>>'.
Types of property 'propTypes' are incompatible.
Type 'WeakValidationMap<InputProps> | undefined' is not assignable to type 'WeakValidationMap<FieldRenderProps<any, HTMLElement>> | undefined'.
Type 'WeakValidationMap<InputProps>' is not assignable to type 'WeakValidationMap<FieldRenderProps<any, HTMLElement>>'.
Types of property 'input' are incompatible.
Type 'Validator<FieldInputProps<string, HTMLInputElement>> | undefined' is not assignable to type 'Validator<FieldInputProps<any, HTMLElement>> | undefined'.
Type 'Validator<FieldInputProps<string, HTMLInputElement>>' is not assignable to type 'Validator<FieldInputProps<any, HTMLElement>>'.
Type 'FieldInputProps<string, HTMLInputElement>' is not assignable to type 'FieldInputProps<any, HTMLElement>'. TS2322
34 | <div className="App">
35 | <Form onSubmit={() => { }} render={() => {
> 36 | return <Field component={Input} name="f"/>
| ^
37 | }}/>
38 | </div>
39 | );
What is the expected behavior?
No type errors. This worked in 6.3.0.
Sandbox Link
https://github.com/Dema/rff-bug
Other information
I think the issue is with a limited type inference that bails out too early.
Here https://github.com/final-form/react-final-form/blame/master/typescript/index.d.ts#L96
T extends HTMLElement = HTMLElement
= HTMLElement
default value forces typescript to give up on trying to infer real type that is HTMLInputElement
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Providing custom error messages for built-in HTML5 form ...
How to customize built-in form validation error messages. Grab the input element(s) with a querySelector / querySelectorAll . Add an event ...
Read more >Custom Common Input Component - Validation Errors not ...
It appears that the ng-invalid class is not added on the input. The component doesn't know MatError, if you change the tag to...
Read more ><input>: The Input (Form Input) element - HTML
The <input> HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide...
Read more >Show custom error on lightning:input
I suggest using reportValidity() because it does all the work for you. The other way to do this (described in other answers) is...
Read more >lightning-record-edit-form - Salesforce Developers
If you use an HTML button element within lightning-record-edit-form , the default is type="submit" . When you submit the form, the component fires...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This issue still happen on the latest react final form version. It is stable on the version “react-final-form”: “^6.3.0”, “final-form”: “^4.18.6”,
Yeah, my bad, I didn’t check if reverting actually fixes the issue. I think I could try to pinpoint exact commit