Skip to content

Commit

Permalink
Merge pull request #1860 from nicholas-l/patch-1
Browse files Browse the repository at this point in the history
Stop crashing on undefined or null properties in flow intersection
  • Loading branch information
ljharb committed Jul 4, 2018
2 parents d225a11 + 87a0818 commit 4e26092
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/prop-types.js
Expand Up @@ -360,7 +360,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
51 changes: 51 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -1872,6 +1872,25 @@ ruleTester.run('prop-types', rule, {
};
`,
parser: 'babel-eslint'
},
{
code: `
// @flow
import * as React from 'react'
type Props = {}
const func = <OP: *>(arg) => arg
const hoc = <OP>() => () => {
class Inner extends React.Component<Props & OP> {
render() {
return <div />
}
}
}
`,
parser: 'babel-eslint'
}
],

Expand Down Expand Up @@ -3627,6 +3646,38 @@ ruleTester.run('prop-types', rule, {
message: '\'fooBar\' is missing in props validation'
}],
parser: 'babel-eslint'
},
{
code: `
type ReduxState = {bar: number};
const mapStateToProps = (state: ReduxState) => ({
foo: state.bar,
});
// utility to extract the return type from a function
type ExtractReturn_<R, Fn: (...args: any[]) => R> = R;
type ExtractReturn<T> = ExtractReturn_<*, T>;
type PropsFromRedux = ExtractReturn<typeof mapStateToProps>;
type OwnProps = {
baz: string,
}
// I want my Props to be {baz: string, foo: number}
type Props = PropsFromRedux & OwnProps;
const Component = (props: Props) => (
<div>
{props.baz}
{props.bad}
</div>
);
`,
errors: [{
message: '\'bad\' is missing in props validation'
}],
parser: 'babel-eslint'
}
]
});

0 comments on commit 4e26092

Please sign in to comment.