reactjs / reactjs/react-docgen
Types from `*.d.ts` files are not parsed in node_modules
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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