From fee2d1a02fe32772129973cf1054a49930934ef8 Mon Sep 17 00:00:00 2001 From: Yannick Croissant Date: Mon, 4 Jun 2018 23:20:04 +0200 Subject: [PATCH] Fix crash in no-unused-prop-types when encountering mixed union and intersection flow types (fixes #1806) --- lib/rules/no-unused-prop-types.js | 2 +- tests/lib/rules/no-unused-prop-types.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-unused-prop-types.js b/lib/rules/no-unused-prop-types.js index b73c173c01..cff7eecafc 100644 --- a/lib/rules/no-unused-prop-types.js +++ b/lib/rules/no-unused-prop-types.js @@ -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); diff --git a/tests/lib/rules/no-unused-prop-types.js b/tests/lib/rules/no-unused-prop-types.js index ba3500045a..b0bc92237b 100644 --- a/tests/lib/rules/no-unused-prop-types.js +++ b/tests/lib/rules/no-unused-prop-types.js @@ -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 { + render() { + return
Hello {this.props.firstname}
+ } + } + `, + parser: 'babel-eslint', + errors: [{ + message: '\'age\' PropType is defined but prop is never used' + }] } /* , {