Skip to content

'type' of undefined when PropTypes.shape on functional component #1471

Closed
@yutin1987

Description

only happened on the functional component, class component it is work.

version

    "eslint": "^4.8.0",
    "eslint-config-airbnb": "^16.0.0",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "eslint-plugin-react": "^7.4.0",

error message

Cannot read property 'type' of undefined
TypeError: Cannot read property 'type' of undefined
    at checkValidPropObject (/Users/yutin/Studio/tmot/hitmot/node_modules/eslint-plugin-react/lib/rules/no-typos.js:76:15)
    at checkValidProp (/Users/yutin/Studio/tmot/hitmot/node_modules/eslint-plugin-react/lib/rules/no-typos.js:65:11)
    at node.properties.forEach.prop (/Users/yutin/Studio/tmot/hitmot/node_modules/eslint-plugin-react/lib/rules/no-typos.js:77:41)
    at Array.forEach (native)
    at checkValidPropObject (/Users/yutin/Studio/tmot/hitmot/node_modules/eslint-plugin-react/lib/rules/no-typos.js:77:25)
    at reportErrorIfClassPropertyCasingTypo (/Users/yutin/Studio/tmot/hitmot/node_modules/eslint-plugin-react/lib/rules/no-typos.js:85:9)
    at MemberExpression (/Users/yutin/Studio/tmot/hitmot/node_modules/eslint-plugin-react/lib/rules/no-typos.js:135:11)
    at listeners.(anonymous function).forEach.listener (/Users/yutin/Studio/tmot/hitmot/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (native)
    at Object.emit (/Users/yutin/Studio/tmot/hitmot/node_modules/eslint/lib/util/safe-emitter.js:47:38)

sample code

function Component({ data }) {
  return (<View />);
}

Component.displayName = 'Channel';

Component.propTypes = {
  data: PropTypes.shape(), // <= this line
};

Component.defaultProps = {
  data: {},
};

export default Component;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions