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

Rule proposal: forbid unspecific prop type definitions #215

Closed
lo1tuma opened this issue Sep 12, 2015 · 1 comment
Closed

Rule proposal: forbid unspecific prop type definitions #215

lo1tuma opened this issue Sep 12, 2015 · 1 comment
Labels

Comments

@lo1tuma
Copy link

lo1tuma commented Sep 12, 2015

Using React.PropTypes.object or React.PropTypes.array is quite unspecific, it tells you nothing about the actual content of a property.

Example:

class Foo extends React.Component {
    render: function () {
        return <div>{this.props.bar.something}</div>
    }
}

Foo.propTypes = {
    bar: React.PropTypes.object.isRequired
};

const foo = <Foo bar={ otherthing: 'foo' } />;

As you can see the object provided for the bar property doesn’t have a property something which is used in the render function.
To avoid such mistakes it would be better to use React.PropTypes.shape and describe how the object should look like:

Foo.propTypes = {
    bar: React.PropTypes.shape({
        something: React.PropTypes.string.isRequired
    })
};

I propose a rule that forbids every usage of:

  • React.PropTypes.object which should be replaced by React.PropTypes.shape
  • React.PropTypes.array which should be replaced by React.PropTypes.arrayOf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants