fix(react): infer constructor return type instead of void - #1037
Open
pmarkert wants to merge 1 commit into
Open
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
generateSignaturefell back tovoidwhenever an entry had noReturns:line. Node's API docs omit that line on constructors by convention, so every
constructor rendered as returning
void— e.g.new Agent(options?): voidonhttp.html. A
constructor never returns
void; it yields an instance of its own class.The third parameter of
generateSignature/createSignatureCodeBlockwas aprefix string (
'new '). It now takes the heading'sHeadingDatainstead, sothe 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 hasno parsable type rendered the literal string
undefined, and now falls back tovoid.Note for reviewers: the old signature accepted an arbitrary prefix string, and a
test covered
'abstract '. That value was never aHeadingType, no caller everproduced it, and its output (
class abstract MyClass extends BaseClass) is notvalid TypeScript — so it was covering an unreachable branch. That test now
asserts a
classheading renders with no prefix.Validation
node --run test— 553 passing, 0 failing. Rewrote the three tests thatexercised the old string-prefix contract, and added coverage for: a constructor
with no
Returns:, a constructor with an explicitReturns:(inference mustnot clobber it), and a return entry with no type.
Rendered locally with
-t weband diffed the signature lines againstbeta.docs.nodejs.org:
http.htmlnew Agent(options?): voidnew Agent(options?): Agenturl.htmlnew URL(input, base?): voidnew URL(input, base?): URLsqlite.htmlnew DatabaseSync(path, options?): voidnew DatabaseSync(path, options?): DatabaseSyncnet.htmlnew net.SocketAddress(options?): voidnew net.SocketAddress(options?): net.SocketAddressAlso verified unchanged:
agent.destroy(): voidand other genuinely-voidmethods still render
void; all fiveclass X extends Ysignatures inhttp.htmlare untouched; the fivenew Buffer(...)overloads each keep theirown 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.mdrenders: Agentwhilenet.mdrenders: net.Socket—consistent within each page, but not across them, because the headings differ
(
### new Agent(...)vs### new net.Socket(...)). Happy to normalise ifyou'd prefer.
Related Issues
Addresses #953 — the constructor
bullets (
net,buffer,fs,http,sqlite,url). The remaining items inthat issue (overloads only annotating the last signature, async-dispose methods,
and source-side missing
Returns:lines) are untouched.Check List
node --run testand all tests passed.node --run format:check&node --run lint.