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

TypeError: Cannot read property 'type' of undefined #579

Closed
d7h opened this issue Apr 28, 2016 · 1 comment
Closed

TypeError: Cannot read property 'type' of undefined #579

d7h opened this issue Apr 28, 2016 · 1 comment
Labels

Comments

@d7h
Copy link

d7h commented Apr 28, 2016

Cannot read property 'type' of undefined
TypeError: Cannot read property 'type' of undefined
at /path/to/src/node_modules/eslint-plugin-react/lib/rules/forbid-prop-types.js:59:14
at Array.forEach (native)
at checkForbidden (/path/to/src/node_modules/eslint-plugin-react/lib/rules/forbid-prop-types.js:55:18)
at EventEmitter.ClassProperty (/path/to/src/node_modules/eslint-plugin-react/lib/rules/forbid-prop-types.js:89:9)
at emitOne (events.js:82:20)
at EventEmitter.emit (events.js:169:7)
at NodeEventGenerator.enterNode (/path/to/src/node_modules/eslint/lib/util/node-event-generator.js:42:22)
at CodePathAnalyzer.enterNode (/path/to/src/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:609:23)
at CommentEventGenerator.enterNode (/path/to/src/node_modules/eslint/lib/util/comment-event-generator.js:99:23)
at Controller.traverser.traverse.enter /path/to/src/node_modules/eslint/lib/eslint.js:887:36)

This happens if I import props from another file and then define another prop in a Component. Like this:

import React from 'react';

import propTypes from './test.propTypes';

class Test extends react.component {

    static propTypes = {
        intl: React.propTypes.number,
        ...propTypes
    };
}

eslint version 2.8.0

@rake5k
Copy link

rake5k commented Apr 29, 2016

The problem lies in the destructuring of the imported propTypes object. To work aroung this issue, just move the intl propType into the test.propTypes file.

import React from 'react';
import propTypes from './test.propTypes'; // contains 'intl: React.propTypes.number'

class Test extends react.component {
    static propTypes = propTypes;
}

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

No branches or pull requests

3 participants