microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.47k stars 12.42k forks source link

please alias jsdoc doc comments to variable assignments #49798

Open trusktr opened 2 years ago

trusktr commented 2 years ago

Suggestion

🔍 Search Terms

typescript alias jsdoc to variable assignment

✅ Viability Checklist

My suggestion meets these guidelines:

⭐ Suggestion

Please copy JSDoc data to aliased variables.

📃 Motivating Example

/** Call this in order to something. */
const foo = (s: string): number => 123

const f = foo

f // hovering on 'f' does not show the documentation description "Call this in order to something."

playground

💻 Use Cases

Make documentation easier. All projects need good documentation!

Workaround:

an author can copy/paste duplicate JSDoc comments. This is harder to maintain.

fregante commented 2 years ago

Just in time! I was looking for exactly this now. I tried several JSDoc options but nothing seems to be able to copy the description the right way (@typedef, @inheritDocs, @borrows, @augments, …)

trusktr commented 2 years ago

Is more feedback needed from me? Or from a team member? Not sure what the tag implies.

remcohaszing commented 2 years ago

Could this also be applied to type aliases too?

/**
 * This is a type
 */
type Foo = string | number

type Bar = Foo

// hovering on 'Bar' does not show the documentation description "This is atype"
export { Bar }

This is especially useful for types in jsdoc

/**
 * @typedef {import('vscode-languageserver-types').Range} Range
 */

// jsdoc information is lost for 'Range'
/**
 * @param {Range} range
 */
function handleRange(range) {}
unional commented 1 year ago
/**
 * what this type is about
 */
export type Foo = () => void

const foo: Foo // `foo` should get `Foo` jsdoc if itself does not have one.
verikono commented 1 year ago

Big props to this... If i get another sermon about semantic reasoning from my boss I think I shall surely die... He's all about those multilevel type aliasing, type branding and guarding and now he's worked out that with async/await everywhere... those type guards are getting very very very composed... unlike myself.

trusktr commented 1 year ago

Here's a video showing the issue:

https://user-images.githubusercontent.com/297678/224135023-6bc4b96a-042b-4f43-845d-f9fac7aa1e64.mov