Description
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 codeThis wouldn't change the runtime behavior of existing JavaScript codeThis could be implemented without emitting different JS based on the types of the expressionsThis 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.
Activity
fatcerberus commentedon Sep 30, 2022
Duplicate of #407
typescript-bot commentedon Oct 3, 2022
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
mesqueeb commentedon Oct 4, 2022
@typescript-bot i think you need to close it as duplicate (the grey one) not as completed (the purple one)