microsoft / TypeScript

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

Support adding JSDoc comments for union constituents #54510

Closed cseas closed 1 year ago

cseas commented 1 year ago

Suggestion

🔍 Search Terms

✅ Viability Checklist

My suggestion meets these guidelines:

⭐ Suggestion

Support adding JSDoc comments for individual union constituents.

📃 Motivating Example

JSDoc comments for union members would appear in IDE IntelliSense (refer below example).

💻 Use Cases

Consider the following type for spacing tokens in a UI library.

type Spacing =
  /** 4px */
  | 'spacing.1'
  /** 8px */
  | 'spacing.2';

We want the equivalent px values of these tokens to be visible in the IDE wherever this type is used in our components for spacing based props. This way our users wouldn't need to refer the library documentation for what the final value of a token is.

Screenshot 2023-06-02 at 8 37 56 AM

Currently this is only possible by building an extension for the IDE, something similar to Tailwind CSS IntelliSense.

Screenshot 2023-06-02 at 11 36 39 AM

We're discussing workarounds here: https://github.com/razorpay/blade/issues/1249

Similar use-case has also been asked on StackOverflow: https://stackoverflow.com/questions/63067208/writing-more-descriptive-intellisense-docs-for-typescript-union-types

cseas commented 1 year ago

Update:

I found this comment in a TSDoc issue that explains the use-case well: https://github.com/microsoft/tsdoc/issues/164#issuecomment-585052389

I see the author has already opened an issue for this but it didn't appear in any of my Google searches (check in Issue description)

Closing as #38106 captures the requirement well.