Skip to content

react/prop-types false positive when component is exported to a different name #2051

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

Closed
bdwain opened this issue Nov 19, 2018 · 6 comments
Closed
Assignees

Comments

@bdwain
Copy link

bdwain commented Nov 19, 2018

I have a component that is giving me false positives saying that a proptype is not defined.

'children' is missing in props validation react/prop-types

Here's an example

import React from 'react';
import PropTypes from 'prop-types';
import makeHoc from './make-hoc';
import selectors from './selectors';

class Foo extends React.Component {
  render() {
    return this.props.children;
  }
}

Foo.propTypes = {
  children: PropTypes.element.isRequired
};

export const Unconnected = Foo; //this line causes the issue
export default makeHoc(
  Foo,
  selectors
);

and it works if I change commented line above to this

export { Foo as Unconnected };

At first I thought #1958 was related but on second look it doesn't seem to be. I also tried downgrading to 7.10.0 and that didn't help.

I don't see anything wrong with that syntax, but please point out if I'm missing something. Thanks!

@ljharb
Copy link
Member

ljharb commented Nov 20, 2018

Certainly the as version is better, since it doesn't create an additional binding inside your module, but the = version should still work.

@bdwain
Copy link
Author

bdwain commented Nov 20, 2018

Agreed. But figured it was still a bug so I'd report it.

@alexzherdev
Copy link
Contributor

Hmm I pasted this entire example as a test for 7.11.1 and it passed

@ljharb
Copy link
Member

ljharb commented Dec 1, 2018

In that case let’s add the test case in a PR and close the issue. It’s possible this is a bug fixed in master but not yet released.

@alexzherdev
Copy link
Contributor

oh cool, according to the build in #2068 this does fail on ESLint 5.

@alexzherdev
Copy link
Contributor

Also, this has been filed before in #1957

@yannickcr yannickcr self-assigned this Jan 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants