microsoft / microsoft/TypeScript

Suggestion: make hover tooltips more readable by showing the generic parameters names instead of their value (in some cases)..

Offen
#62,634 3 Kommentare 1 Reaktion 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
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

🔍 Search Terms

tooltip generic parameters
expandable hover
format hover

Related issues:

I searched for both open and close issues, didn't found a duplicate, maybe I didn't use the correct search terms.

✅ Viability Checklist
⭐ Suggestion

For readability sake, when displaying type info in the hover tooltip, it is better (in some cases) to show the generic parameters' names instead of their value.

The rule could be that when a generic type parameter exceed a certain size, to show its name instead of its value (with the possibility to expand it).

📃 Motivating Example
function foo<T extends Record<string, any>>(o: T) {
    return class X {
        constructor(a: number, b: string) {}
    }
}

const X = foo({
    f1: 34, f2: 34, f3: 34, f4: 34, f5: 34, f6: 34, f7: 34, f8: 34, f9: 34, f10: 34,
});

new X(12, "ok")

Playground Link

When editing new X() arguments, the following tooltip is showing:

X(a: number, b: string): foo<{ f1: number; f2: number; f3: number; f4: number; f5: number; f6: number; f7: number; f8: number; f9: number; f10: number; }>.X

This can quickly become hard to read if the generic parameters are complex. The following would be easier to read (while keeping the ability to expand it*).

X(a: number, b: string): foo<T>.X

_*Well, maybe expansion is not always the solution, and instead of showing the full type definition, to be able to browse the type, e.g. clicking on "T" to show its value (in another hover or by expanding it). Could be more appropriate when we want more precision on one part of the type, not on the whole type.

*Note: TS Playground doesn't seem to have the expandable hover tooltip feature._

💻 Use Cases
  1. What do you want to use this for?

Improve hover tooltip readability.

  1. What shortcomings exist with current approaches?

Tooltip can be hard to read.

  1. What workarounds are you using in the meantime?

Some VSCode extensions, enable to "prettify" hover tooltips to some extends (e.g. MylesMurphy.prettify-ts).

The alternative would be to format the output to improve readability:

X(
        a: number,
        b: string
): foo<
            { f1: number; f2: number; f3: number; f4: number; f5: number; f6: number; f7: number; f8: number; f9: number; f10: number; }
      >.X

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

Reproduziere das motivierende Beispiel mit dem verlinkten TypeScript Playground und untersuche die gemeldete Ausgabe des Hover-Tooltips. Es ist keine Repository-Datei, kein Test und kein Implementierungseinstiegspunkt angegeben, daher muss zuerst die Größenschwelle, das Erweiterungsverhalten und die erwartete Darstellung von generischen Parametern geklärt werden. Erledigt ist die Aufgabe, wenn die Hover-Ausgabe besser lesbar ist und gleichzeitig eine geeignete Möglichkeit erhalten bleibt, den zugrunde liegenden Typ zu untersuchen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
developer-experience, tooling
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.