简体   繁体   English

TypeScript 的 Eslint 反应/道具类型错误

[英]Eslint react/prop-types error with TypeScript

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:我收到 Eslint 错误:使用以下看似有效的示例对 React 组件的接口使用extends'age' is missing in props validation eslint (react/prop-types)

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?这是我没有完全掌握的错误还是功能?

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 .万一有人偶然发现这个问题,正如问题评论中提到的,这里有一个关于这个验证规则的问题: 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 eslintrc.js文件中的规则

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM