Skip to content

An alternative @overload syntax for JSDoc #52796

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

Open
5 tasks done
rdking opened this issue Feb 16, 2023 · 2 comments
Open
5 tasks done

An alternative @overload syntax for JSDoc #52796

rdking opened this issue Feb 16, 2023 · 2 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@rdking
Copy link

rdking commented Feb 16, 2023

Suggestion

πŸ” Search Terms

jsdoc
function
overload

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Here's an alternative thought on the syntax that could satisfy PR #52474 without causing parser issues mentioned in PR #52577. What if overload simply allowed you to declare a method signature? For instance:

/**
 * @overload { (inst, klass, members) => object }
 * @overload { (inst, members) => undefined }
 * @param {object} inst
 * @param {function} klass
 * @param {object} members
 * @returns {object|undefined}
 */
function share(inst, klass, members) {}

This should be both easy to parse, and satisfy the user's needs while allowing for minimally redundant documentation, all in a single comment.

@fatcerberus
Copy link

I was under the impression that the main purpose of @overload was to allow you to have separate documentation (summary text, parameter descriptions, etc.) for each overload, like you can already do in TS. Consolidating them like this would defeat the purpose.

@rdking
Copy link
Author

rdking commented Feb 18, 2023

Not true, or at least not with the way I envision it functioning when generating documentation. The presence of 2 or more @overload tags would have the effect of producing a function definition for each @overload supplied. The params given in the @overload tag would be used as a filter in the list of params within the jsdoc comment. The net effect of the above would be documented as if the example below didn't cause the latter to replace the former:

/**
 * @function share
 * @param {object} inst
 * @param {function} klass
 * @param {object} members
 * @returns {object}
 */
/**
 * @function share
 * @param {object} inst
 * @param {object} members
 * @returns {undefined}
 */

If it is actually beneficial for there to be completely separate documentation for each overload (usually unlikely), then that could be satisfied by having separate comment blocks with only 1 @overload tag allowed. However, that case of a single tag would not allow a function definition to be specified with it. In that case, the example in my OP would be equivalent to:

/**
 * @override
 * @function share
 * @param {object} inst
 * @param {function} klass
 * @param {object} members
 * @returns {object}
 */
/**
 * @override
 * @function share
 * @param {object} inst
 * @param {object} members
 * @returns {undefined}
 */

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants