Closed
Description
The folllowing code causes a false positive for the react/proptypes, with 'className' missing in prop-types declaration. Since this is typescript, and ComponentProps includes className, I'd expect this to not happen.
import * as React from "react";
type ComponentProps = {
className?: string;
};
class Test {
getAComponent(): React.FC<ComponentProps> {
return function ComponentName(props: ComponentProps): React.ReactElement {
return <div className={props.className}>Hello</div>;
};
}
}
const test = new Test();
const Comp = test.getAComponent();
export default function App(): React.ReactElement {
return (
<div className="App">
<Comp className="text-success" />
</div>
);
}
If the component is instead defined outside of the method that returns it, then the warning dissapears, like this (the rest of the example remains the same):
const getAComponentNotInClass = function ComponentName(props: ComponentProps): React.ReactElement {
return <div className={props.className}>Hello</div>;
};
class Test {
getAComponent(): React.FC<ComponentProps> {
return getAComponentNotInClass
}
}