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

Cannot read property 'filter' of undefined (require-default-props) #1043

Closed
CarlRosell opened this issue Jan 25, 2017 · 3 comments
Closed

Cannot read property 'filter' of undefined (require-default-props) #1043

CarlRosell opened this issue Jan 25, 2017 · 3 comments

Comments

@CarlRosell
Copy link
Contributor

CarlRosell commented Jan 25, 2017

Hi!
Just updated my packages and now I get this error from eslint:

Cannot read property 'filter' of undefined
TypeError: Cannot read property 'filter' of undefined
    at getPropTypesFromTypeAnnotation (/$PROJECT$/node_modules/eslint-plugin-react/lib/rules/require-default-props.js:167:29)
    at handlePropTypeAnnotationClassProperty (/$PROJECT$/node_modules/eslint-plugin-react/lib/rules/require-default-props.js:287:42)
    at Object.ClassProperty (/$PROJECT$/node_modules/eslint-plugin-react/lib/rules/require-default-props.js:458:11)
    at EventEmitter.updatedRuleInstructions.(anonymous function) (/$PROJECT$/node_modules/eslint-plugin-react/lib/util/Components.js:581:75)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.enterNode (/$PROJECT$/node_modules/eslint/lib/util/node-event-generator.js:39:22)
    at CodePathAnalyzer.enterNode (/$PROJECT$/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:607:23)
    at CommentEventGenerator.enterNode (/$PROJECT$/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
    at Controller.enter (/$PROJECT$/node_modules/eslint/lib/eslint.js:928:36)

My package.json looks something like:

{
    "eslint": "3.14.0",
    "eslint-config-airbnb": "14.0.0",
    "eslint-loader": "1.6.1",
    "eslint-plugin-flowtype": "2.30.0",
    "eslint-plugin-import": "2.2.0",
    "eslint-plugin-jsx-a11y": "3.0.2",
    "eslint-plugin-react": "6.9.0"
}

I manage to fix the problem in react-default-props.js by checking if annotation.properties does exist inside of getPropTypesFromTypeAnnotation-function

function getPropTypesFromTypeAnnotation(node) {
      var properties;

      switch (node.typeAnnotation.type) {
        case 'GenericTypeAnnotation':
          var annotation = resolveGenericTypeAnnotation(node.typeAnnotation);
          properties = annotation && annotation.properties ? annotation.properties : [];
                                  ^^^^^^^^^^^^^^^^^^^^^^^^

I could send a PR for this fix if you want. But I'm not familiar with the whole codebase to know if it would break somewhere else.

@ljharb
Copy link
Member

ljharb commented Jan 25, 2017

Please do send a PR if you're also able to include a failing test :-)

@CarlRosell
Copy link
Contributor Author

Fixed by #1018 and test added in #1045

@josomers
Copy link

josomers commented Feb 7, 2017

Hi, as I'm having the same issue (and this is already resolved) I was wondering when the next release is planned?

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

No branches or pull requests

3 participants