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

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

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.

yannickcr added a commit that referenced this issue Jun 4, 2018
nicholas-l added a commit to nicholas-l/eslint-plugin-react that referenced this issue Jun 28, 2018
Similar to other fix for flow intersection (jsx-eslint#1806)
calebeby pushed a commit to Pigmice2733/scouting-frontend that referenced this issue Jun 30, 2018
This Pull Request updates dependency [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) from `v7.9.1` to `v7.10.0`



<details>
<summary>Release Notes</summary>

### [`v7.10.0`](https://github.com/yannickcr/eslint-plugin-react/blob/master/CHANGELOG.md#&#8203;7100---2018-06-24)
[Compare Source](jsx-eslint/eslint-plugin-react@v7.9.1...v7.10.0)
##### Added
* Allow eslint ^5 ([#&#8203;1843][] @&#8203;papandreou, @&#8203;ljharb)
* [`no-unsafe`][] rule ([#&#8203;1831][], [#&#8203;1830][] @&#8203;sergei-startsev)
* [`no-will-update-set-state`][]: Account for `UNSAFE_` methods ([#&#8203;1845][], [#&#8203;1844][] @&#8203;alexzherdev)
##### Fixed
* [`no-typos`][]: Fix static propTypes handling ([#&#8203;1827][], [#&#8203;1677][] @&#8203;alexzherdev)
* [`destructuring-assignment`][]: Allow LHS ([#&#8203;1825][], [#&#8203;1728][] @&#8203;alexzherdev)
* [`no-unused-prop-types`][]: Fix crash when encountering mixed union and intersection flow types ([#&#8203;1806][] @&#8203;yannickcr)
##### Changed
* Typo fixes in [`jsx-no-target-blank`][] ([#&#8203;1805][] @&#8203;ferhatelmas))

[#&#8203;1845]: `jsx-eslint/eslint-plugin-react#1845
[#&#8203;1844]: `jsx-eslint/eslint-plugin-react#1844
[#&#8203;1843]: `jsx-eslint/eslint-plugin-react#1843
[#&#8203;1831]: `jsx-eslint/eslint-plugin-react#1831
[#&#8203;1830]: `jsx-eslint/eslint-plugin-react#1830
[#&#8203;1827]: `jsx-eslint/eslint-plugin-react#1827
[#&#8203;1825]: `jsx-eslint/eslint-plugin-react#1825
[#&#8203;1806]: `jsx-eslint/eslint-plugin-react#1806
[#&#8203;1805]: `jsx-eslint/eslint-plugin-react#1805
[#&#8203;1728]: `jsx-eslint/eslint-plugin-react#1728
[#&#8203;1677]: `jsx-eslint/eslint-plugin-react#1677

---

</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).
This was referenced Sep 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants