Skip to content

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

Closed
@carlrosell

Description

@carlrosell

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.

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