Skip to content

fix(react): infer constructor return type instead of void - #1037

Open
pmarkert wants to merge 1 commit into
nodejs:mainfrom
pmarkert:fix/constructor-return-types
Open

fix(react): infer constructor return type instead of void#1037
pmarkert wants to merge 1 commit into
nodejs:mainfrom
pmarkert:fix/constructor-return-types

Conversation

@pmarkert

Copy link
Copy Markdown

Description

generateSignature fell back to void whenever an entry had no Returns:
line. Node's API docs omit that line on constructors by convention, so every
constructor rendered as returning void — e.g. new Agent(options?): void on
http.html. A
constructor never returns void; it yields an instance of its own class.

The third parameter of generateSignature / createSignatureCodeBlock was a
prefix string ('new '). It now takes the heading's HeadingData instead, so
the function derives both the prefix and the return-type fallback from the
heading type rather than having them passed in pre-computed. Constructors fall
back to their own class name; everything else still falls back to void.

This also fixes a smaller related bug: a Returns: entry that exists but has
no parsable type rendered the literal string undefined, and now falls back to
void.

Note for reviewers: the old signature accepted an arbitrary prefix string, and a
test covered 'abstract '. That value was never a HeadingType, no caller ever
produced it, and its output (class abstract MyClass extends BaseClass) is not
valid TypeScript — so it was covering an unreachable branch. That test now
asserts a class heading renders with no prefix.

Validation

node --run test — 553 passing, 0 failing. Rewrote the three tests that
exercised the old string-prefix contract, and added coverage for: a constructor
with no Returns:, a constructor with an explicit Returns: (inference must
not clobber it), and a return entry with no type.

Rendered locally with -t web and diffed the signature lines against
beta.docs.nodejs.org:

before after
http.html new Agent(options?): void new Agent(options?): Agent
url.html new URL(input, base?): void new URL(input, base?): URL
sqlite.html new DatabaseSync(path, options?): void new DatabaseSync(path, options?): DatabaseSync
net.html new net.SocketAddress(options?): void new net.SocketAddress(options?): net.SocketAddress

Also verified unchanged: agent.destroy(): void and other genuinely-void
methods still render void; all five class X extends Y signatures in
http.html are untouched; the five new Buffer(...) overloads each keep their
own distinct parameters.

Where a page already had an explicit Returns: on its constructor
(net.Server, net.Socket), the inferred value matches it exactly.

One judgment call worth a maintainer's opinion: the fallback uses the displayed
name, so http.md renders : Agent while net.md renders : net.Socket
consistent within each page, but not across them, because the headings differ
(### new Agent(...) vs ### new net.Socket(...)). Happy to normalise if
you'd prefer.

Related Issues

Addresses #953 — the constructor
bullets (net, buffer, fs, http, sqlite, url). The remaining items in
that issue (overloads only annotating the last signature, async-dispose methods,
and source-side missing Returns: lines) are untouched.

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:check & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

generateSignature fell back to `void` for any entry without a
`Returns:` line. Node's API docs omit that line on constructors by
convention, so every constructor rendered as returning `void` —
e.g. `new Agent(options?): void` on http.html.

Pass the heading metadata through so constructors fall back to their
own class name instead.

Refs: nodejs#953

Signed-off-by: Phillip Markert <phillip@ephisys.com>
@pmarkert
pmarkert requested a review from a team as a code owner August 13, 2026 20:42
@vercel

vercel Bot commented Aug 13, 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 Aug 13, 2026 8:43pm

Request Review

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.

1 participant