Skip to content

Destructuring 'prop-types' results in "no-typos" False Positive #2136

Closed
@r-mc2

Description

@r-mc2

(I took a look at other open issues here and found some related but none pointing at exactly this)

I prefer to destructure the exact types I need from the prop-types package rather than pull the whole thing in and dot-syntax to what I need. This seems to be a missing case in the rule file where it only makes two assumptions:

  • Importing from the new package: import PropTypes from 'prop-types';
  • Importing from the old react package: import { PropTypes } from 'react';

In my case I go with:

import { string, element } from "prop-types";

class Sample {
 ...
}

Sample.propTypes = {
  title: string.isRequired,
  body: element.isRequired
};

Both of the above cause a "Typo in declared prop-type: isRequired". Which in digging through the code makes sense as it appears that because I do not use PropTypes.string.isRequired it is looking for isRequired inside the known types list in the prop-types. And when not found in its iteration the test fails and I get the false-positive.

I'm not entirely sure how to add support for this use-case of prop-types but I'm pretty sure it's this if-block that would also need some work as this is where the logic is falling through to test string.isRequired with the same check responsible for testing PropTypes.string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions