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

Union error with Flow types #1770

Closed
EdwardDrapkin opened this issue Apr 17, 2018 · 0 comments · Fixed by #1860
Closed

Union error with Flow types #1770

EdwardDrapkin opened this issue Apr 17, 2018 · 0 comments · Fixed by #1860

Comments

@EdwardDrapkin
Copy link

Seems that if I declare a union type for my props, this plugin dies:

$ eslint --fix src/ test/
Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at iterateProperties (/Users/edwarddrapkin/projects/flex-mobile-head/node_modules/eslint-plugin-react/lib/rules/prop-types.js:363:22)
    at declarePropTypesForObjectTypeAnnotation (/Users/edwarddrapkin/projects/flex-mobile-head/node_modules/eslint-plugin-react/lib/rules/prop-types.js:744:7)
    at propTypes.types.some.annotation (/Users/edwarddrapkin/projects/flex-mobile-head/node_modules/eslint-plugin-react/lib/rules/prop-types.js:783:16)
    at Array.some (<anonymous>)
    at declarePropTypesForIntersectionTypeAnnotation (/Users/edwarddrapkin/projects/flex-mobile-head/node_modules/eslint-plugin-react/lib/rules/prop-types.js:766:30)
    at markPropTypesAsDeclared (/Users/edwarddrapkin/projects/flex-mobile-head/node_modules/eslint-plugin-react/lib/rules/prop-types.js:864:35)
    at Program:exit.classExpressions.forEach.node (/Users/edwarddrapkin/projects/flex-mobile-head/node_modules/eslint-plugin-react/lib/rules/prop-types.js:1123:13)
    at Array.forEach (<anonymous>)
    at Program:exit (/Users/edwarddrapkin/projects/flex-mobile-head/node_modules/eslint-plugin-react/lib/rules/prop-types.js:1121:26)
    at listeners.(anonymous function).forEach.listener (/Users/edwarddrapkin/projects/flex-mobile-head/node_modules/eslint/lib/util/safe-emitter.js:47:58)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This type declaration triggers the error:


type Props = {
    style: typeof style & StyleObj,
    isValid: false,
    errorText: string
} | {
    style: typeof style & StyleObj,
    isValid: true,
    caption: string,
    icon?: Node
};

This one does not, but is less useful:

type Props = {
    style: typeof style,
    isValid: true,
    errorText?: string,
    caption?: string,
    icon?: Node
};

I'm on version 7.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants