microsoft / microsoft/TypeScript
Error Messages Related to Nested Identical Generic Names Could Be More Explicit
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the nested generic example from the issue, comparing the diagnostics produced when the inner generic is named T with the version that uses the outer T. Trace the TypeScript type-checker diagnostic path for these errors and define the work as complete when nested identical generic labels are distinguished without changing runtime output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100