Skip to content

no-unused-prop-types crashes when props type is intersection with union #1806

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

Closed
thers opened this issue Jun 4, 2018 · 2 comments
Closed

Comments

@thers
Copy link

thers commented Jun 4, 2018

A code like this:

import * as React from 'react';

type OtherProps = {} | {};

type Props = OtherProps & {};

class Test extends React.PureComponent<Props> {}

will lead to:

Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at iterateProperties (/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:364:22)
    at declarePropTypesForObjectTypeAnnotation (/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:764:7)
    at propTypes.types.some.annotation (/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:807:16)
    at Array.some (<anonymous>)
    at declarePropTypesForIntersectionTypeAnnotation (/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:790:30)
    at markPropTypesAsDeclared (/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:869:35)
    at Object.ClassDeclaration (/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:992:11)
    at EventEmitter.updatedRuleInstructions.(anonymous function) (/node_modules/eslint-plugin-react/lib/util/Components.js:698:75)
    at emitOne (events.js:121:20)
    at EventEmitter.emit (events.js:211:7)

It's worth to mention that type Props = ({} | {}) & {}; won't crash, but type Props = (string) & {} will fail with:

Cannot read property 'name' of undefined
TypeError: Cannot read property 'name' of undefined
    at propTypes.types.some.annotation (/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:799:50)
    at Array.some (<anonymous>)
    at declarePropTypesForIntersectionTypeAnnotation (/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:790:30)
    at markPropTypesAsDeclared (/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:869:35)
    at Object.ClassDeclaration (/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:992:11)
    at updatedRuleInstructions.(anonymous function) (/node_modules/eslint-plugin-react/lib/util/Components.js:698:75)
    at listeners.(anonymous function).forEach.listener (/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/node_modules/eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (/node_modules/eslint/lib/util/node-event-generator.js:251:26)

Plugin version is 7.9.1.

@ljharb
Copy link
Member

ljharb commented Jun 4, 2018

Probably unrelated, but import * as React is always incorrect - it’s only import React from ‘react’. Can you confirm you’re using flow? Usually only old and broken TypeScript docs ask for that incorrect syntax.

@thers
Copy link
Author

thers commented Jun 4, 2018

Yes, I am using flow, and that is indeed unrelated as it crashes no matter if this line present or not.

This was referenced Sep 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment