reactjs / reactjs/react-docgen

Types from `*.d.ts` files are not parsed in node_modules

Open
#929 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

If an installed package would deliver type informations with d.ts files, it won't parse these files and interface informations are missing in the props.

It could be fixed in the makeFsImporter.ts file with a simple addition:

if (!nextFile) {
      // Customization: try to read from a "d.ts" file instead, if it exists
      if (resolvedSource.includes("node_modules")) {
        const dtsPath = resolvedSource.replace(".js", ".d.ts");
        if (fs.existsSync(dtsPath)) {
          resolvedSource = dtsPath;
        }
      }
      // Customization: end

      // Read and parse the code
      const src = fs.readFileSync(resolvedSource, "utf8");

      nextFile = file.parse(src, resolvedSource);

      parseCache.set(resolvedSource, nextFile);
}

But i didn't want to make another pull request because i'm not sure if this is a nice way to solve it.

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 in makeFsImporter.ts and trace how unresolved files under node_modules are read and parsed. Check the existing handling around resolvedSource and parseCache, then verify that installed packages exposing .d.ts files produce the expected interface information in component props.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.