Skip to content

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

Description

@suesslin

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

Activity

  1. added
    docIssues and PRs related to Node.js documentation.
    feature requestIssues requesting new Node.js features.
    on Aug 4, 2017
  2. TimothyGu commented on Aug 4, 2017

    @TimothyGu
    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().

  3. Fishrock123 commented on Aug 4, 2017

    @Fishrock123
    Contributor

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

  4. suesslin commented on Aug 4, 2017

    @suesslin
    Author

    @Fishrock123 A reasoning would be nice

  5. Fishrock123 commented on Aug 4, 2017

    @Fishrock123
    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.)

  6. gibfahn commented on Aug 13, 2017

    @gibfahn
    Member

    @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?

  7. suesslin commented on Aug 13, 2017

    @suesslin
    Author

    @gibfahn That sounds amazing!

  8. lpinca commented on Oct 1, 2017

    @lpinca
    Member

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

  9. gibfahn commented on Oct 1, 2017

    @gibfahn
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.feature requestIssues requesting new Node.js features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions