PropType已定义但从未使用过eslint错误

时间:2020-01-31 10:42:13

标签: reactjs eslint react-proptypes

在对直接变形的对象使用预定义的常量SHAPE时,出现eslint错误react/no-unused-proptypes

f.e。

import React from 'react';
import PropTypes from 'prop-types';

const View = ({
    foo: {
        bar,
    },
}) => (
    <div>{ bar }</div>
);

const PREDEFINED_SHAPE = PropTypes.shape({
    bar: PropTypes.string,
});

View.propTypes = {
    foo: PREDEFINED_SHAPE.isRequired,
};

/*
 * When predefined shape is not used, the error dissapears
 * f.e.
 * *

View.propTypes = {
    foo: PropTypes.shape({
        bar: PropTypes.string,
    }).isRequired,
};

*/

export default View;

为什么不允许第一种方式,或者只是带有eslint的某些错误?

我正在使用eslint版本:

  • “ babel-eslint”:“ ^ 10.0.3”,
  • “夹板”:“ ^ 4.19.1”,
  • “ eslint-config-airbnb”:“ ^ 15.0.1”,
  • “ eslint-import-resolver-webpack”:“ ^ 0.8.4”,
  • “ eslint-loader”:“ ^ 1.7.1”,
  • “ eslint-plugin-import”:“ ^ 2.3.0”,
  • “ eslint-plugin-jsx-a11y”:“ ^ 5.0.3”,
  • “ eslint-plugin-react”:“ ^ 7.0.1”,

0 个答案:

没有答案