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

[Fix]: use variable value in prop type field defined by a variable #2704

Merged

Conversation

jzabala
Copy link
Contributor

@jzabala jzabala commented Jul 9, 2020

Use the variable value in cases where the type is given by a variable. Example:

const firstType = PropTypes.shape({
  id: PropTypes.number,
});
class ComponentX extends React.Component {
  static propTypes = {
    first: firstType.isRequired, // resolve to `first: PropTypes.shape({ id: PropTypes.number }).isRequired`
  };
  render() {
    return (
      <div>
        {/*Correctly validates that first.name is not defined in propTypes.*/}
        <div>Counter = {this.props.first.name}</div>
      </div>
    );
  }
}

Fixes #2236

@ljharb ljharb force-pushed the fix/validate-prop-types-from-variables branch from 0e0de41 to 5bab611 Compare July 9, 2020 05:31
@ljharb ljharb merged commit 5bab611 into jsx-eslint:master Jul 9, 2020
@jzabala jzabala deleted the fix/validate-prop-types-from-variables branch August 13, 2020 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

ESLint doesn't validate props if they are exported to a var or module.
2 participants