Skip to content

fix(metadata): support TS prefix operators in typeParser#883

Open
moshams272 wants to merge 2 commits into
nodejs:mainfrom
moshams272:fix/type-parser-prefixes
Open

fix(metadata): support TS prefix operators in typeParser#883
moshams272 wants to merge 2 commits into
nodejs:mainfrom
moshams272:fix/type-parser-prefixes

Conversation

@moshams272

Copy link
Copy Markdown
Contributor

Description

Currently, the typeParser in src/generators/metadata/utils/typeParser.mjs fails to resolve types that have prefix operators such as typeof, keyof, readonly, and unique.

Because the parser treats the prefix and the target type as a single continuous string (e.g., "typeof Compiler"), it fails to find a match in the type-map, resulting in dead links and plain text rendering in the documentation.

This PR introduces a check for these common prefix operators before falling back to array or generic processing. It strips the prefix, formats it as plain text, and recursively passes the remaining target type to resolveOr so it can be correctly matched and linked.

Validation

Tested it on webpack-doc-kit:

Before:
image

After:
image

Related Issues

No related issues.

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

@moshams272 moshams272 requested a review from a team as a code owner July 5, 2026 08:29
@vercel

vercel Bot commented Jul 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Jul 5, 2026 4:07pm

Request Review

@cursor

cursor Bot commented Jul 5, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Small, localized change to documentation type-string parsing with new unit tests; no auth, data, or runtime API impact.

Overview
Fixes doc metadata type linking when TypeScript prefix operators wrap a known type (e.g. typeof Compiler), which previously failed type-map lookup and rendered as plain text.

Adds a shared PREFIXES list (typeof , keyof , readonly , unique ) and, in parseType, detects these at the start of a trimmed type (after union/intersection/=> handling, before [] and generics). The prefix is kept as plain text and the remainder is passed through resolveOr so the base name can be linked.

Unit tests cover successful typeof linking and that identifiers like typeofSomething are not split because matching requires the trailing space after the keyword.

Reviewed by Cursor Bugbot for commit 48fa635. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.02%. Comparing base (9c5f11f) to head (48fa635).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #883      +/-   ##
==========================================
+ Coverage   85.00%   85.02%   +0.02%     
==========================================
  Files         179      179              
  Lines       16453    16479      +26     
  Branches     1491     1496       +5     
==========================================
+ Hits        13986    14012      +26     
  Misses       2457     2457              
  Partials       10       10              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/generators/metadata/utils/typeParser.mjs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants