Skip to content

prop-types rule reports for Array.prototype.length is missing #1047

Closed
@ashleahhill

Description

@ashleahhill

h2. Expected

When a propType React.PropTypes.arrayOf(<something>), you shouldn't be prompted to add
length by eslint.

h2. What happens

You get '.length' is missing in props validation (react/prop-types) from eslint

h2. Example

class MyClass extends React.Component {
    static propTypes = {
        results: PropTypes.arrayOf(
            PropTypes.shape({
                items: PropTypes.arrayOf(PropTypes.shape(<Shape definition>))
            })
        )
    };

    get hasItems() {
        this.props.results && this.props.results.items && this.props.results.items.length > 0; 
    }
}

Results in this:
'results.items.length' is missing in props validation (react/prop-types)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy