microsoft / microsoft/TypeScript
Evaluate user-defined generic type aliases on hover
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Usa gli esempi TypeScript nell'issue come riproduzione: confronta l'output dell'hover per il mapped type inline, l'Exclude integrato e l'alias InitialiserExclude definito dall'utente. Inizia tracciando il comportamento dell'hover del servizio del linguaggio per questi tipi. Il lavoro è completato quando, passando il mouse sul parametro del costruttore, l'alias definito dall'utente viene espanso nel tipo oggetto risultante.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- developer-experience
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100