Skip to content

intellisense for JSDocs on function overloads without needing to duplicate the JSDoc #51005

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

Closed
5 tasks done
mesqueeb opened this issue Sep 30, 2022 Β· 3 comments
Closed
5 tasks done
Labels
Duplicate An existing issue was already created

Comments

@mesqueeb
Copy link

mesqueeb commented Sep 30, 2022 β€’

Suggestion

πŸ” Search Terms

  • intellisense for JSDocs on function overloads without needing to duplicate the JSDoc
  • auto complete
  • JSDocs
  • function overloads

βœ… 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

When you have a really long JSDoc that describes a function (say 10+ lines) and you need 3~4 function overloads for that function. The only way to properly have the JSDocs show up on all overload cases when you actually import and use the function is to duplicate the JSDocs for each single function overload...

FR: We need VSCode intellisense for our JSDocs to show up on ALL function overloads without needing to duplicate the JSDocs on every overload.

πŸ“ƒ Motivating Example

Here is a very common example I use countless of times throughout my code where an object that's potentially undefined is parsed in a function, but when we know the payload is not undefined we want to make sure the return type is also not.

type Person = { firstName: string; lastName: string }
type PersonParsed = { fullName: string }

export function parsePerson(person: Person): PersonParsed
export function parsePerson(person: undefined): undefined
export function parsePerson(person: Person | undefined): PersonParsed | undefined
export function parsePerson(person?: Person): PersonParsed | undefined {
  // ... implementation
}

A perfect use-case for function overloads! But then comes your detailed JSDoc and it will look like this:

type Person = { firstName: string; lastName: string }
type PersonParsed = { fullName: string }

/**
 * Here is a very long JSDoc
 *
 * Maybe it describes what the function can do / when it should be used
 * - Maybe it has
 * - some bullet lists
 *
 * @see https://some-related-documentation...
 * @example
 * ```js
 * // some usage examples:
 * const { fullname } = parsePerson(person) || {}
 * console.log(`fullname β†’ `, fullname)
 * ```
 */
export function parsePerson(person: Person): PersonParsed
/**
 * Here is a very long JSDoc
 *
 * Maybe it describes what the function can do / when it should be used
 * - Maybe it has
 * - some bullet lists
 *
 * @see https://some-related-documentation...
 * @example
 * ```js
 * // some usage examples:
 * const { fullname } = parsePerson(person) || {}
 * console.log(`fullname β†’ `, fullname)
 * ```
 */
export function parsePerson(person: undefined): undefined
/**
 * Here is a very long JSDoc
 *
 * Maybe it describes what the function can do / when it should be used
 * - Maybe it has
 * - some bullet lists
 *
 * @see https://some-related-documentation...
 * @example
 * ```js
 * // some usage examples:
 * const { fullname } = parsePerson(person) || {}
 * console.log(`fullname β†’ `, fullname)
 * ```
 */
export function parsePerson(person: Person | undefined): PersonParsed | undefined
/**
 * Here is a very long JSDoc
 *
 * Maybe it describes what the function can do / when it should be used
 * - Maybe it has
 * - some bullet lists
 *
 * @see https://some-related-documentation...
 * @example
 * ```js
 * // some usage examples:
 * const { fullname } = parsePerson(person) || {}
 * console.log(`fullname β†’ `, fullname)
 * ```
 */
export function parsePerson(person?: Person): PersonParsed | undefined {
  // ... implementation
}

πŸ’» Use Cases

Use case explained in the previous section.

Conclusion

We need VSCode intellisense for our JSDocs to show up on ALL function overloads without needing to duplicate the JSDocs on every overload.

@fatcerberus
Copy link

Duplicate of #407

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Sep 30, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@mesqueeb
Copy link
Author

mesqueeb commented Oct 4, 2022

@typescript-bot i think you need to close it as duplicate (the grey one) not as completed (the purple one)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants