Skip to content

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

@yutin1987

Description

@yutin1987

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;

Metadata

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy