microsoft / microsoft/TypeScript

Evaluate user-defined generic type aliases on hover

Offen
#43,275 0 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

Let's say we have a class like this:

class A
{
    readonly x = 99;
    s: string;

    constructor(initialiser: { [K in Exclude<keyof A, 'x'>]: A[K] })
    {
        for (const k in initialiser) this[k] = initialiser[k];
    }
}

Now, when I hover over the ctor param, VS Code shows me the type: { s: string; }.

Since I need such an initialiser for several classes, I have written a generic type alias:

type InitialiserExclude<C, Keys extends keyof C> = { [K in Exclude<keyof C, Keys>]: C[K] };

When I replace the initialiser type by InitialiserExclude<A, 'x'>, that's exactly what I see when hovering over the ctor param.

It would be very nice if VS Code evaluated such user-defined type aliases as it does with e. g. the built-in Exclude<T, U> and showed the resulting object type.

This is not only a matter of usability of the class. To create more complex initialiser types, it can be necessary to define multiple generic type aliases and use one within another, and the only way I know to check if such an initialiser works as expected is to declare a variable with that type and hover over it.

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

Verwende die TypeScript-Beispiele im Issue als Reproduktion: Vergleiche die Hover-Ausgabe für den Inline-Mapped-Type, das integrierte Exclude und den benutzerdefinierten InitialiserExclude-Alias. Beginne damit, das Hover-Verhalten des Language Service für diese Typen nachzuverfolgen. Als erledigt gilt, wenn beim Hover über den Konstruktorparameter der benutzerdefinierte Alias zum resultierenden Objekttyp erweitert wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
developer-experience
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
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.