microsoft / microsoft/TypeScript

Error Messages Related to Nested Identical Generic Names Could Be More Explicit

Aperta
#42,423 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: Error Messages Experience Enhancement Needs Proposal Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Suggestion

🔍 Search Terms

identical generics
overlapping generics
nested generics

✅ Viability Checklist

My suggestion meets these guidelines (please notify me if my checklist is incorrect):

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

⭐ Suggestion

Modify generic-related error messages, that involve 2 or more nested, identically named generic labels, to be more explicit.
e.g. Append "(which is a different type from the first 'T')" (or something similar) to the original message.

📃 Motivating Example

The following error message was caused by a function nested within a function using the same generic label (as well as some erroneous code.) I suggest we modify generic-related error messages where there are 2 or more nested generic labels that have the same name. A more explicit message would help nudge the developer towards the real error source.

image

Here is a snippet of the actual source code:

export function useForm<T extends FormFieldData>() {
  // ...
  function<T extends FormFieldData>(input: FormFieldKeys<T>) {
    // ...
  }
}

The solution in this case was removing the unnecessary nested generic and using the useForm scoped generic:

export function useForm<T extends FormFieldData>() {
  // ...
  function (input: FormFieldKeys<T>) {
    // ...
  }
}

@DanielRosenwasser @sandersn

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

Inizia riproducendo l’esempio generico annidato dell’issue, confrontando le diagnosi prodotte quando il generico interno è denominato T con la versione che usa il T esterno. Traccia il percorso diagnostico del type checker di TypeScript per questi errori e considera completato il lavoro quando le etichette generiche identiche annidate vengono distinte senza modificare l’output a runtime.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.