reactjs / reactjs/react-docgen

How to generate correct prop types when the prop-types package is not explicitly imported?

Open
#595 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

new feature
Dominant language
TypeScript
Stars
3.8k
Forks
316
Avg merge
5h 7m
Merged PRs (30d)
4

Description

Is there a recommended way to generate prop types when the prop-types package is not explicitly imported into each component? For example, in my project, PropTypes is provided as a global through webpack's providePlugin:

config: {
    plugins: [
        new ProvidePlugin({
               PropTypes: 'prop-types',
        }),
    ]
};

So PropTypes is available to any react component—even when it is not imported.

I see the resolveToModule util looks for the prop-types import, and if it is not found, we end up with custom prop types rather than their actual type, like string or bool. It seems I can create a handler to generate prop types even when the prop-types package is not explicitly imported, but is there an already existing handler or other way to do this that addresses this case?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the resolveToModule util and the existing handlers for prop-types. Reproduce the case where webpack ProvidePlugin supplies PropTypes without an explicit prop-types import, then determine whether an existing handler supports it; done when generated output reports concrete types such as string or bool instead of custom.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, webpack
Domain
documentation, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.