-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
prop-types
rule reports for Array.prototype.find is missing
#2477
Comments
prop-types
rule reports for Array.prototype.find is missingprop-types
rule reports for Array.prototype.find is missing
What happens with other array methods? I’d definitely expect this to work with PropTypes.array, but I’m not sure if it’s been tested with the TS array type. |
I have example code that shows the same problem with Array.length, using the TS array type.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Any update on this? import React from 'react';
interface MyProps {
myListOfNumbers: number[];
}
const myComponent = ({myListOfNumbers}: MyProps): JSX.Element => {
const createMyResult = (): JSX.Element => {
return (<h2>{myListOfNumbers.join(',')}</h2>); // FAILS - 'myListOfNumbers.join' is missing in props validation eslint(react/prop-types)
};
return <>
<h1>{
myListOfNumbers.join(',') // OK
}</h1>
{createMyResult()}
</>;
};
export default myComponent; Our issue seems to be related to that it wants some sort of extra prop validation on an inner helper method that returns JSX. Even if the inner function uses the props from parent component. |
@Cnordbo |
@ljharb I think @Cnordbo gave us just a small example and
I don't think |
They definitely do, and those should be detected. I think it's totally reasonable for the component detection to detect when a function that returns jsx is defined with a name that isn't valid to use inside jsx - a PR would be welcome. |
if this had been a component function inside a component function, then it would have been defined as a component using PascalCase. I believe React gives out an error as well if i were to use it as a component without an uppercase first character. Using it as a component yields the following error in TypeScript: Changing the name to My point here is that it should recognize @ljharb Reading your comment, i think your saying the same thing? |
I am. |
The title explains everything i guess, I'm using eslint-plugin-react in a javascript migrated to typescript project.
Here is a simple version of my code:
The text was updated successfully, but these errors were encountered: