Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop crashing on undefined or null properties in flow intersection #1860

Merged
merged 3 commits into from
Jul 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rules/prop-types.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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'
}
]
});