microsoft / microsoft/TypeScript

Preserve property comment and insert @default value, if provided

Offen
#41,486 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Search Terms

default initial initializer value preserve comment tsdoc type options option bag

Suggestion

As the title suggests, insert a @default comment to the TSDoc AST if an initializer is provided, preserving the original comment.

Use Cases

I have a default value for an option and I want the consumer of the library to know what the default value is.

Examples

interface Options {
  /**
   * The server host.
   */
  host?: string;
  port?: number;
}

function serve({ host = 'localhost', port }: Options) {
  return { host, port };
}

Playground

Hovering over host in the return statement shows the following in vscode:

Screen Shot 2020-11-10 at 6 39 31 PM

Not only is the TSDoc comment lost for this property, but it could furthermore be improved if @default "localhost" were added to it, seeing as that information is available in this context.

It should look like this:

Screen Shot 2020-11-10 at 6 49 35 PM

Much ❤️ for the TS team!

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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

In der Issue werden keine Quelldateien oder Tests genannt. Beginne damit nachzuverfolgen, wie TypeScript TSDoc ASTs und Hover-Informationen für destrukturierte Parameter erstellt, und prüfe anschließend, wie ein Initialisierer den ursprünglichen Property-Kommentar beibehalten und einen @default-Wert hinzufügen kann. Als abgeschlossen gilt die Aufgabe, wenn das gezeigte Host-Beispiel seinen Kommentar beibehält und den Standardwert offenlegt, ohne das emittierte JavaScript zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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