Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add false to error union at InputProps #511

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

2bfe26
Copy link
Contributor

@2bfe26 2bfe26 commented Jul 5, 2023

Description

When using the Formik, it is common to use the following pattern

<Input
  name="holderName"
  label="Cardholder Name"
  error={formik.touched.holderName && formik.errors.holderName}
  onChange={formik.handleChange}
  onBlur={formik.handleBlur}
  onClean={onClean('holderName')}
/>

It is a very convenient way to pass the error. The expression formik.touched.holderName && formik.errors.holderName always returns a string or false. The component checks if the error is falsy and returns null in the error section if it is.

The only problem is when using the "strict" mode of TypeScript:
Type 'string | false | undefined' is not assignable to type 'string | undefined'.

I believe it's worth allowing the value "false" for these cases to work, but I don't think it makes sense to allow the Boolean type itself since the value "true" would likely be serialized and displayed on the screen.

@sonarcloud
Copy link

sonarcloud bot commented Jul 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
10.6% 10.6% Duplication

Copy link
Contributor

@MarcosViniciusPC MarcosViniciusPC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that the adjustment made eliminates type warnings in VS Code but running the project I saw that in the console a warning is displayed when the prop 'error' is passed with value 'false'. Does this behavior occur for you? I think it has something to do with the PropType of the 'error' prop

image

@MarcosViniciusPC MarcosViniciusPC added question Further information is requested and removed status:ready to review labels Aug 1, 2023
@2bfe26
Copy link
Contributor Author

2bfe26 commented Aug 2, 2023

@MarcosViniciusPC I was not aware of this warning, so I'll investigate a little further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested status:fixing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants