Skip to content

Commit

Permalink
Fix crash in no-unused-prop-types when encountering mixed union and i…
Browse files Browse the repository at this point in the history
…ntersection flow types (fixes #1806)
  • Loading branch information
yannickcr committed Jun 4, 2018
1 parent d779865 commit fee2d1a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-unused-prop-types.js
Expand Up @@ -361,7 +361,7 @@ module.exports = {
and property value. (key, value) => void
*/
function iterateProperties(properties, fn) {
if (properties.length && typeof fn === 'function') {
if (properties && properties.length && typeof fn === 'function') {
for (let i = 0, j = properties.length; i < j; i++) {
const node = properties[i];
const key = getKeyValue(node);
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Expand Up @@ -4551,6 +4551,29 @@ ruleTester.run('no-unused-prop-types', rule, {
errors: [{
message: '\'defaultValue\' PropType is defined but prop is never used'
}]
}, {
// Mixed union and intersection types
code: `
import React from 'react';
type OtherProps = {
firstname: string,
lastname: string,
} | {
fullname: string
};
type Props = OtherProps & {
age: number
};
class Test extends React.PureComponent<Props> {
render() {
return <div>Hello {this.props.firstname}</div>
}
}
`,
parser: 'babel-eslint',
errors: [{
message: '\'age\' PropType is defined but prop is never used'
}]
}

/* , {
Expand Down

0 comments on commit fee2d1a

Please sign in to comment.