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

Feature request: propTypes shape detection #62

Closed
lencioni opened this issue Apr 14, 2015 · 1 comment
Closed

Feature request: propTypes shape detection #62

lencioni opened this issue Apr 14, 2015 · 1 comment

Comments

@lencioni
Copy link
Collaborator

Now that we have the prop-types rule, it would be nice if it could be configured to (perhaps by default) help you find properties on objects from props that you are using. For instance:

const React = require('react/addons');

const MyComponent = React.createClass({
  propTypes: {
    myObj: React.PropTypes.object,
  },

  /**
   * @return {Object}
   */
  render: function() {
    const { myObj } = this.props;

    return (
      <div>{myObj.body}</div>
    );
  }
});

module.exports = MyComponent;

It would be nice if this plugin told me that myObj.body is missing from the shape of myObj. Where this would not raise any warnings/errors:

const React = require('react/addons');

const MyComponent = React.createClass({
  propTypes: {
    myObj: React.PropTypes.shape({
      body: PropTypes.string,
    }),
  },

  /**
   * @return {Object}
   */
  render: function() {
    const { myObj } = this.props;

    return (
      <div>{myObj.body}</div>
    );
  }
});

module.exports = MyComponent;
@yannickcr
Copy link
Member

Sorry, I don't think I'll do it, at least not for now.
It should be really difficult to do this properly without missing a lot of edges cases.

But if someone has a solution I can accept a PR :)

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

No branches or pull requests

2 participants