This ESLint plugin enforces the use of aliased (named) types for React component props. It ensures that props are defined using named interfaces or type aliases instead of inline types.
To install the plugin, run:
npm install @patrickemoore/eslint-plugin-aliased-props --save-dev
To configure the plugin in your ESLint configuration file, add the following:
{
"plugins": ["@patrickemoore/aliased-props"],
"rules": {
"@patrickemoore/aliased-props/require-aliased-props": "error"
}
}
const MyComponent = (props: { name: string, age: number }) => {
return <div>{props.name}</div>;
};
type Props = {
name: string,
age: number,
};
const MyComponent = (props: Props) => {
return <div>{props.name}</div>;
};