question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type error when using custom HtmlInput component.

See original GitHub issue

What 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:open
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
luisnoresvcommented, May 5, 2020

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”,

1reaction
Demacommented, Jul 2, 2020

Yeah, my bad, I didn’t check if reverting actually fixes the issue. I think I could try to pinpoint exact commit

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found