microsoft / microsoft/TypeScript

Default type parameter values always shown on hover

Aperta
#59,385 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

default parameters hover

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://tsplay.dev/mpkKgN

💻 Code
export abstract class Kind<
    hkt extends (...args: any[]) => unknown = (...args: any[]) => unknown
> {
    declare readonly args: unknown
    abstract readonly hkt: hkt
}

// Hover: Kind<(...args: any[]) => unknown>
type SomeHkt = Kind
🙁 Actual behavior

Kind's defaulted parameter is displayed on hover.

🙂 Expected behavior

Defaultable generic parameters should not be printed if they are unset in the instantiation and/or explicitly set to their default value.

This could also apply to .d.ts, although that's viewed less often.

Additional information about the issue

This is obviously not a bug but a request that would help reduce visual clutter for many types. Types with several parameters with non trivial default values are relatively common, especially when those defaults are expanded recursively.

It also occurred to me that when combined with autofixes, this could also make types written to a user file much more usable. When using --isolatedDeclarations, one of the biggest problems with the autofixes is that they'd often pull in types with several generic parameters with long defaults, and end up writing some massive type instead of just a single identifier.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Non viene indicato alcun file sorgente né alcun test. Inizia dal TypeScript Playground collegato e ispeziona l'hover per SomeHkt, quindi segui il percorso del compilatore che formatta i parametri di tipo generici. Il lavoro è completo quando i parametri con valore predefinito vengono omessi se non impostati o se esplicitamente uguali ai relativi valori predefiniti, inclusi i casi .d.ts e isolatedDeclarations indicati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers, developer-experience
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.