microsoft / microsoft/TypeScript
Error Messages Related to Nested Identical Generic Names Could Be More Explicit
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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.

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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das verschachtelte generische Beispiel aus dem Issue zu reproduzieren, und vergleiche die erzeugten Diagnosen, wenn das innere Generic T genannt wird, mit der Version, die das äußere T verwendet. Verfolge den TypeScript-Typprüfer-Diagnosepfad für diese Fehler und definiere die Arbeit als abgeschlossen, wenn verschachtelte identische Generic-Bezeichnungen unterschieden werden, ohne die Laufzeitausgabe zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100