Skip to content

Commit fee2d1a

Browse files
committed
Fix crash in no-unused-prop-types when encountering mixed union and intersection flow types (fixes #1806)
1 parent d779865 commit fee2d1a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/rules/no-unused-prop-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ module.exports = {
361361
and property value. (key, value) => void
362362
*/
363363
function iterateProperties(properties, fn) {
364-
if (properties.length && typeof fn === 'function') {
364+
if (properties && properties.length && typeof fn === 'function') {
365365
for (let i = 0, j = properties.length; i < j; i++) {
366366
const node = properties[i];
367367
const key = getKeyValue(node);

tests/lib/rules/no-unused-prop-types.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4551,6 +4551,29 @@ ruleTester.run('no-unused-prop-types', rule, {
45514551
errors: [{
45524552
message: '\'defaultValue\' PropType is defined but prop is never used'
45534553
}]
4554+
}, {
4555+
// Mixed union and intersection types
4556+
code: `
4557+
import React from 'react';
4558+
type OtherProps = {
4559+
firstname: string,
4560+
lastname: string,
4561+
} | {
4562+
fullname: string
4563+
};
4564+
type Props = OtherProps & {
4565+
age: number
4566+
};
4567+
class Test extends React.PureComponent<Props> {
4568+
render() {
4569+
return <div>Hello {this.props.firstname}</div>
4570+
}
4571+
}
4572+
`,
4573+
parser: 'babel-eslint',
4574+
errors: [{
4575+
message: '\'age\' PropType is defined but prop is never used'
4576+
}]
45544577
}
45554578

45564579
/* , {

0 commit comments

Comments
 (0)