Rules
no-prop-types
Full Name in eslint-plugin-react-x
react-x/no-prop-typesFull Name in @eslint-react/eslint-plugin
@eslint-react/no-prop-typesPresets
xrecommendedrecommended-typescriptrecommended-type-checked
Description
Disallow propTypes in favor of TypeScript or another type-checking solution.
PropTypes were deprecated in April 2017 (v15.5.0).
The propType checks will be removed from the React package, and using them will be silently ignored. If you’re using propTypes, it is recommend to migrate to TypeScript or another type-checking solution.
Examples
Failing
import React from "react";
class MyComponent extends React.Component {
static propTypes = {
name: React.PropTypes.string,
};
render() {
return <div>{this.props.name}</div>;
}
}import React from "react";
class MyComponent extends React.Component {
render() {
return <div>{this.props.name}</div>;
}
}
MyComponent.propTypes = {
name: propTypes.string,
};import React from "react";
function MyComponent(props) {
return <div>{props.name}</div>;
}
MyComponent.propTypes = {
name: propTypes.string,
};Passing
import React from "react";
interface MyComponentProps {
name: string;
}
class MyComponent extends React.Component<MyComponentProps> {
render() {
return <div>{this.props.name}</div>;
}
}import React from "react";
interface MyComponentProps {
name: string;
}
function MyComponent({ name }: MyComponentProps) {
return <div>{name}</div>;
}Implementation
Further Reading
See Also
no-default-props
Disallows usingdefaultPropsproperty in favor of ES6 default parameters.