Skip to content

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

Open
@rvetere

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.

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