-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
react/prop-types - False positive when ternary conditional return #2786
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
Comments
This is caused by two things:
Duplicate of #2777. |
Actually this is a different case with #2777 . Below is what happen in #2777 // Error 'item' is missing in props validation react/prop-types
const MyFc: React.FC<Props> = ({ item }) => { }
// No error, fix with define the props type explicitely
const MyFc: React.FC<Props> = ({ item }: Props) => { } However, the issue that I am facing only happen specifically when a ternary condition is used for the return. To address your point 2,
... = ({ item }: Props) = ....
// Proper type had been assigned again explicitely |
Should be fixed, tested with your use case locally - works, although I don't see how the ternary thing makes a difference, this seems like a corollary #3045
|
A PR adding that test case would be a great way to close this issue :-) |
this should be closed, imo cc @ljharb |
Thanks, closed by #3051. |
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
eslint --fix . --ext .ts,.tsx,.js,.jsx
What did you expect to happen?
There should not be an error because
item
had been declared with typeany
.What actually happened? Please include the actual, raw output from ESLint.
How do you verify the source of problem
I had tried the following code, which eslint no longer throw error.
The text was updated successfully, but these errors were encountered: