Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Return type in function declaration & possible option to view types by clicking in doc #14624

Closed
suesslin opened this issue Aug 4, 2017 · 8 comments
Labels
doc Issues and PRs related to the documentations. feature request Issues that request new features to be added to Node.js.

Comments

@suesslin
Copy link

suesslin commented Aug 4, 2017

While working with Node.js, I found having the return types of a function (If given) in the function declaration instead of somewhere in the paragraph below it (As seen in the example following) might improve the documentation.

Example screenshot

Further on, it would most likely be useful to be able to click on the types. Both suggestions are popular documentation features, example is the Rust Documentation

Here a screenshot of what I mean
Example screenshot

@vsemozhetbyt vsemozhetbyt added doc Issues and PRs related to the documentations. feature request Issues that request new features to be added to Node.js. labels Aug 4, 2017
@TimothyGu
Copy link
Member

Most functions (not url.parse() it seems, unfortunately) have a "Returns: " bit, like urlSearchParams.entries(). While a good idea, I'm somewhat worried that writing the returned type would crowd the heading too much for a function with long parameter names like url.parse().

@Fishrock123
Copy link
Contributor

Yeah I'm not really for putting it in the heading either

@suesslin
Copy link
Author

suesslin commented Aug 4, 2017

@Fishrock123 A reasoning would be nice

@Fishrock123
Copy link
Contributor

Easiest argument against it is that that would break links to the docs. Fixing that would probably be non-trivial in the build tooling.

Another is that the return type is already listed.

That being said, while we do have some function with different "argument signatures", it just doesn't operate int he same was a typed language does and as such I'm not certain the same notation is desirable.

Finally, this gets really messy when dealing with async functions that call callbacks with data. (Which most of the significant API is.)

@gibfahn
Copy link
Member

gibfahn commented Aug 13, 2017

@Luki would #13769 help?

The arrow syntax works really well in Rust, as that's how return types are shown in the source code, so it's really intuitive.

I think making sure a - Returns: {Type} is the first thing after the function definition should be pretty clear, WDYT?

@suesslin
Copy link
Author

@gibfahn That sounds amazing!

@lpinca
Copy link
Member

lpinca commented Oct 1, 2017

Closing this, discussion can continue on the closed thread if needed.

@lpinca lpinca closed this as completed Oct 1, 2017
@gibfahn
Copy link
Member

gibfahn commented Oct 1, 2017

The Returns syntax I mentioned is now in the style guide, so feel free to raise PRs to add Returns: anywhere that needs it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

6 participants