Skip to content

Commit 4e26092

Browse files
authored
Merge pull request #1860 from nicholas-l/patch-1
Stop crashing on undefined or null properties in flow intersection
2 parents d225a11 + 87a0818 commit 4e26092

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

lib/rules/prop-types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ module.exports = {
360360
and property value. (key, value) => void
361361
*/
362362
function iterateProperties(properties, fn) {
363-
if (properties.length && typeof fn === 'function') {
363+
if (properties && properties.length && typeof fn === 'function') {
364364
for (let i = 0, j = properties.length; i < j; i++) {
365365
const node = properties[i];
366366
const key = getKeyValue(node);

tests/lib/rules/prop-types.js

+51
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,25 @@ ruleTester.run('prop-types', rule, {
18721872
};
18731873
`,
18741874
parser: 'babel-eslint'
1875+
},
1876+
{
1877+
code: `
1878+
// @flow
1879+
import * as React from 'react'
1880+
1881+
type Props = {}
1882+
1883+
const func = <OP: *>(arg) => arg
1884+
1885+
const hoc = <OP>() => () => {
1886+
class Inner extends React.Component<Props & OP> {
1887+
render() {
1888+
return <div />
1889+
}
1890+
}
1891+
}
1892+
`,
1893+
parser: 'babel-eslint'
18751894
}
18761895
],
18771896

@@ -3627,6 +3646,38 @@ ruleTester.run('prop-types', rule, {
36273646
message: '\'fooBar\' is missing in props validation'
36283647
}],
36293648
parser: 'babel-eslint'
3649+
},
3650+
{
3651+
code: `
3652+
type ReduxState = {bar: number};
3653+
3654+
const mapStateToProps = (state: ReduxState) => ({
3655+
foo: state.bar,
3656+
});
3657+
// utility to extract the return type from a function
3658+
type ExtractReturn_<R, Fn: (...args: any[]) => R> = R;
3659+
type ExtractReturn<T> = ExtractReturn_<*, T>;
3660+
3661+
type PropsFromRedux = ExtractReturn<typeof mapStateToProps>;
3662+
3663+
type OwnProps = {
3664+
baz: string,
3665+
}
3666+
3667+
// I want my Props to be {baz: string, foo: number}
3668+
type Props = PropsFromRedux & OwnProps;
3669+
3670+
const Component = (props: Props) => (
3671+
<div>
3672+
{props.baz}
3673+
{props.bad}
3674+
</div>
3675+
);
3676+
`,
3677+
errors: [{
3678+
message: '\'bad\' is missing in props validation'
3679+
}],
3680+
parser: 'babel-eslint'
36303681
}
36313682
]
36323683
});

0 commit comments

Comments
 (0)