The below checks fine in version 7.20.5 and throws these errors in 7.20.6.
error propType "width" is not required, but has no corresponding defaultProps declaration react/require-default-props
error propType "height" is not required, but has no corresponding defaultProps declaration react/require-default-props
export type Item = {
name: string;
label: string;
};
type Props = Item & {
width?: 'regular' | 'large';
height?: number;
};
const MyComponent = ({
name,
label,
height = 8,
width = 'regular',
}: Props) => {
return ...
}
Note from https://github.com/yannickcr/eslint-plugin-react/issues/2762#issuecomment-681202088
7.20.5 did not support typescript TSTypeAliasDeclaration and TSIntersectionType, so eslint ignored the propType check.
After upgrade to 7.20.6, this feature is supported, so it will do the propType check
This seems correct to me. Default values aren't the same as defaultProps, and the rule is meant to force .defaultProps.
Sorry for the confusion.
According to document:
One advantage of defaultProps over custom default logic in your code is that defaultProps are resolved by React before the PropTypes typechecking happens, so typechecking will also apply to your defaultProps. The same also holds true for stateless functional components: default function parameters do not behave the same as defaultProps and thus using defaultProps is still preferred.
So default values are not the same as defaultProps.
We are using typescript in our project.
Do we have any benefit from adding .defaultProps and additional PropType checking?