4

I'm getting the Eslint error: 'age' is missing in props validation eslint (react/prop-types) when using extends for interface for React components using the below seemingly valid example:

interface SuperProps {
  age: number;
}

interface TestProps extends SuperProps {
  name: string;
}

const Test = ({ name, age }: TestProps) => {
  return (
    <p>
      {name}: {age}
    </p>
  );
};

Is this a bug or a feature that I haven't fully grasped?

4
  • 1
    I believe it to be a bug in package "eslint-plugin-react", because that's a completely valid interface and it should work just fine, but the plugin can't find the props defined in the parent interface. Commented Jul 9, 2020 at 13:38
  • 2
    @TelmoTrooper - you're probably right, found this issue that I think is the correct one: github.com/yannickcr/eslint-plugin-react/issues/2654 Strange that this could pass through the checkpoints without being noticed, it should be a common enough pattern. Commented Jul 9, 2020 at 13:43
  • 2
    Since you are using TS probably there's not need to use eslint checks for prop types and it can be disabled in .eslintrc this way: "react/prop-types": "off"' Commented Nov 10, 2021 at 8:59
  • 1
    Thanks, not really solving the issue. Seems though that the issue has been closed and I haven't tested the functionality lately. Commented Nov 10, 2021 at 20:26

1 Answer 1

4

In case anyone stumbles upon this question, as mentioned in the question comments there was an issue raised regarding this validation rule here: https://github.com/yannickcr/eslint-plugin-react/issues/2654.

The issue is closed but it seems it is not resolved. The validation rule can be disabled by adding

'react/require-default-props': 0

to the rules in your eslintrc.js file

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.