microsoft / microsoft/TypeScript

Support for comments inside JSDoc @example comments

Offen
#52,398 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Domain: JSDoc In Discussion Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Suggestion

🔍 Search Terms:

comments inside jsdoc, jsdoc inception

✅ 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

I am writing a custom helper type that allows me to provide JSDoc comments for properties of any other object or interface that is inaccessible for changes.
I need to document the feature and usage, but I can't close a comment section inside JSDoc comment's.

Code:

image

/**
 * This type allows to add JSDoc annotation to any type without causing conflicts.
 *
 * @example
 * type IconButtonProps =
 *  & JSDoc
 *  & ShorthandVariantsAndSizes
 *
 * type JSDoc = Documentation<ShorthandVariantsAndSizes, {
 *  /**
 *   * **variant**: Color theme for the button.
 *   * - `light` variant is white on all themes.
 *   \*\/
 *   variant?: unknown  // <- note: this `?: unknown` optional type is important
 * }>
 */
type Documentation<T, TargetType extends { [K in keyof T]?: unknown }> = TargetType

JSDoc invoked:

image

💻 Use Cases

Desired:

image

Result:

image

📃 Motivating Example

const sizeKeys = ['small', 'large'] as const

// this is a mapped type and therefore doesn't allow to add JSDoc comments
type ExplodedSizes = { [key in typeof sizeKeys]?: unknown }

type JSDoc = Documentation<ExplodedSizes, {
  /**
   * **size**: Button size.
   * - `64px`
   */
  large?: unknown
  /**
   * **size**: Button size.
   * - `32px`
   */
  small?: unknown
}>

// this merges the jsdoc annotation with correct types
export type IconButtonProps =
  & JSDoc
  & ExplodedSizes

export const IconButton: React.FC<IconButtonProps> = (props) => <> </> 

// later when using the component
const render = <IconButton /> // <- gets correct intellisense with JSDoc comments here

image

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Es werden keine Quelldateien oder Tests genannt. Beginne damit nachzuverfolgen, wie TypeScript JSDoc-Blöcke mit @example und verschachtelte Kommentarbegrenzer verarbeitet, und vergleiche dann die gezeigte Eingabe mit der gewünschten Dokumentationsdarstellung. Fertig ist es, wenn Kommentare innerhalb eines @example-Blocks erhalten bleiben, ohne das bestehende JSDoc-Verhalten zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.