Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yutin1987 opened this issue Oct 11, 2017 · 9 comments
Closed

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

yutin1987 opened this issue Oct 11, 2017 · 9 comments

Comments

@yutin1987
Copy link

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;
@ljharb
Copy link
Member

ljharb commented Oct 11, 2017

Is the error fixed if you add {} inside the shape call?

@yutin1987
Copy link
Author

yutin1987 commented Oct 11, 2017

oh!! thank you. {} is required. add {} inside will be fixed.

@ljharb
Copy link
Member

ljharb commented Oct 11, 2017

I've never seen shape used without an object literal, but React doesn't require it, and regardless, we shouldn't crash on it.

@neiker
Copy link

neiker commented Oct 17, 2017

+1 to don't fail on this

@mrichmond
Copy link

Yup... this got me too.

@mrichmond
Copy link

Once the bug is fixed... perhaps a new rule for no-undefined-shape?

@ljharb
Copy link
Member

ljharb commented Jan 3, 2018

Fixed in #1504.

@ljharb ljharb closed this as completed Jan 3, 2018
@ljharb ljharb mentioned this issue Jan 12, 2018
@FDiskas
Copy link

FDiskas commented Jan 7, 2019

    "eslint-config-airbnb": "17.1.0",
    "eslint-config-prettier": "3.3.0",
    "eslint-plugin-flowtype": "3.2.0",
    "eslint-plugin-immutable": "1.0.0",
    "eslint-plugin-import": "2.14.0",
    "eslint-plugin-jsx-a11y": "6.1.2",
    "eslint-plugin-prettier": "3.0.1",
    "eslint-plugin-react": "7.12.3",
[Error - 11:14:02 PM] TypeError: Cannot read property 'type' of undefined
    at resolveSuperParameterPropsType (***/node_modules/eslint-plugin-react/lib/util/propTypes.js:574:20)
    at Object.ClassDeclaration (***/node_modules/eslint-plugin-react/lib/util/propTypes.js:610:39)
    at updatedRuleInstructions.(anonymous function) (***/node_modules/eslint-plugin-react/lib/util/Components.js:706:43)

@ljharb
Copy link
Member

ljharb commented Jan 7, 2019

@FDiskas please file a new issue; commenting on a closed issue isn't going to help anything get fixed.

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

No branches or pull requests

5 participants